调用DLL文件中的FORM

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

作者:e梦缘

好久发表文章了!!!

调用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;

....

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航