u_form1.~pas

来自「很好地delphi书籍源码」· ~PAS 代码 · 共 62 行

~PAS
62
字号
unit U_Form1;

interface

uses
  SysUtils, Windows, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, Spin;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    SpinEdit1: TSpinEdit;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type
  TIntFunction = function (I: Integer): Integer; stdcall;

procedure TForm1.Button1Click(Sender: TObject);
var
  HInst: THandle;
  FPointer: TFarProc;
  MyFunct: TIntFunction;
begin
  HInst := LoadLibrary ('FuncDll.dll');
  if HInst > 0 then
  try
    FPointer := GetProcAddress (HInst,
      PChar (ComboBox1.Text));
    if FPointer <> nil then
    begin
      MyFunct := TIntFunction (FPointer);
      Edit1.Text :=ComboBox1.Text+
                   Format('计算结果:%d',[MyFunct (SpinEdit1.Value)]);
    end
    else
      ShowMessage ('DLL function not found');
  finally
    FreeLibrary (HInst);
  end
  else
    ShowMessage ('Library not found');
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?