⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dcall4.pas

📁 本光盘是《Delphi 7应用教程》一书的配套光盘
💻 PAS
字号:
unit DCall4;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Label3: TLabel;
    Edit2: TEdit;
    Button3: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation


{$R *.dfm}
  type
    TIntFunction=Function(arr:String):Integer;stdcall;
    TBoolFunction=Function(arr:String):Boolean;stdcall;
procedure TForm1.Button2Click(Sender: TObject);
var
  Dllname:string;
  Hinst:Thandle;
  ProcName:Pchar;
  Fpointer:TFarProc;
  MyFunctInt:TIntFunction;
  MyFunctBool:TBoolFunction ;
  k:integer;
begin
  getdir(0,Dllname);
  Dllname:=dllname+'\FUNDLL4.dll';
    if ComboBox1.Text ='字母字符个数' then
           begin
              k:=1;
              ProcName:='AlphNum';
           end
       else
           if  ComboBox1.Text ='数字字符个数' then
                 begin
                     k:=2;
                     ProcName:='DigNum';
                 end
                 else
                     begin
                        k:=3;
                        ProcName:='HuiWen';
                     end;
    Hinst:=SafeLoadLibrary(Dllname);
    if Hinst>0 then
      try
         Fpointer:=GetProcAddress(HInst,ProcName);
         if Fpointer<>Nil then
            begin
               if(k=1) or (k=2)  then
                 begin
                     MyfunctInt:=TIntFunction(Fpointer);
                     Edit2.text:=inttostr(MyfunctInt(edit1.text));
                 end
                 else
                     begin
                        MyfunctBool:=TBoolFunction(Fpointer);
                        if MyfunctBool(edit1.text) then
                           edit2.Text :='是回文'
                         else
                            edit2.Text :='不是回文'
                     end;
            end
           else
              showmessage('DLL Function not found.');
      Finally
         FreeLibrary(Hinst);
      end
      else
         ShowMessage(Dllname+' Library not Found');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Application.Terminate ;
end;

end.

⌨️ 快捷键说明

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