作者: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;exportsshowform;beginend.
....procedure  RunDllForm(const DllFileName,DllFormName:String;const methodName:string);typeTRunForm=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);beginRunDllForm('project1.dll','form1','showform');end;....新聞熱點
疑難解答