delphi 调用DLL文件中的FORM


本文整理自网络,侵删。

  library Project1;

uses
SysUtils,
   Classes,Forms,windows,dialogs,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
function showform(formname:string):boolean;stdcall;
var
  TheClass: TPersistentClass;
  aForm: TForm;
begin
result:=false;
{如果您的Dll中有很多FORM,请在这儿注册哦
RegisterClasses([TForm1,TForm2,TForm3,...]);
}
RegisterClasses([TForm1]);
TheClass := GetClass('T' + FormName);
if (TheClass = nil) then   exit;
if TheClass.InheritsFrom(TForm)  then
begin
    aForm := Tform(TheClass.Create).Create(nil);
    try
      aForm.ShowModal;
      result:=true;
    finally
      FreeAndNil(aForm);
    end;

end;
end;

exports
showform;
begin
end.


  
  
....


procedure  RunDllForm(const DllFileName,DllFormName:String;const methodName:string);
type
TRunForm=function(formname:string):boolean;stdcall;
var
  RunForm: TRunForm;
  GetDllHWND: HWND;
begin
  GetDllHWND := LoadLibrary(PChar(DllFileName));
  try
    if GetDllHWND < 32 then
    begin
      MessageBox(0, Pchar('没有找到'+DllFileName+'DLL文件!'),'加载DLL失败', MB_OK);
      Exit;
    end;
    @RunForm := GetProcAddress(GetDllHWND,pchar(methodName));
    if @RunForm <> nil then
       try
         RunForm(DllFormName);
       except
         raise Exception.Create('对不起,找不到T' + DllFormName+ '窗体!');
       end
     else
     raise Exception.Create('无效的方法名调用');
  finally
    FreeLibrary(GetDllHWND);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
RunDllForm('project1.dll','form1','showform');
end;

相关阅读 >>

Delphi xe 启动关闭start page 页错误提示

Delphi android gps服务

Delphi indy smtp 发送邮件

Delphi 组件篇 之 tbevel组件

Delphi使用spcomm串口通信 串口号大于10出错的解决办法

incsecond:将一个tdatetime变量加减一定数量的秒数

Delphi开发linux包

Delphi 检测一个网络连接是否有效带超时

Delphi 读cpu串号的代码

Delphi xe10 手机端错误提示:detected problems with api compatibility (visit g.co/dev/appcompat for more info

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...