调用DLL文件中的FORM<br><br><br>调用DLL文件中的FORM,具体实现过程如下:<br><br>library Project1;<br><br>uses<br> SysUtils,<br> Classes,Forms,windows,dialogs,<br> Unit1 in 'Unit1.pas' {Form1};<br><br>{$R *.res}<br>function showform(formname:string):boolean;stdcall;<br>var<br> TheClass: TPersistentClass;<br> aForm: TForm;<br>begin<br> result:=false;<br> {如果您的Dll中有很多FORM,请在这儿注册哦<br> RegisterClasses([TForm1,TForm2,TForm3,...]);<br> }<br> RegisterClasses([TForm1]);<br> TheClass := GetClass('T' + FormName);<br> if (TheClass = nil) then exit;<br> if TheClass.InheritsFrom(TForm) then<br> begin<br> aForm := Tform(TheClass.Create).Create(nil);<br> try<br> aForm.ShowModal;<br> result:=true;<br> finally<br> FreeAndNil(aForm);<br> end;<br><br> end;<br>end;<br><br>exports<br>showform;<br>begin<br>end.<br><br><br><br>--------------------------------------------------------------------------------<br><br><br><br>....<br><br><br>procedure RunDllForm(const DllFileName,DllFormName:String;const methodName:string);<br>type<br>TRunForm=function(formname:string):boolean;stdcall;<br>var<br> RunForm: TRunForm;<br> GetDllHWND: HWND;<br>begin<br> GetDllHWND := LoadLibrary(PChar(DllFileName));<br> try<br> if GetDllHWND &lt; 32 then<br> begin<br> MessageBox(0, Pchar('没有找到'+DllFileName+'DLL文件!'),'加载DLL失败', MB_OK);<br> Exit;<br> end;<br> @RunForm := GetProcAddress(GetDllHWND,pchar(methodName));<br> if @RunForm &lt;&gt; nil then<br> try<br> RunForm(DllFormName);<br> except<br> raise Exception.Create('对不起,找不到T' + DllFormName+ '窗体!');<br> end<br> else<br> raise Exception.Create('无效的方法名调用');<br> finally<br> FreeLibrary(GetDllHWND);<br> end;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>RunDllForm('project1.dll','form1','showform');<br>end;<br><br><br>....<br> <br>上面的例子没有释放过程,自己最后别忘了<br>取消注册