一、新建一個DlL文件
1.新建一個Dll文件,並保存Dll文件
二、將EXE的.pas文件添加到Dll文件中
1.點擊 Project -->Add Project(或Shift+F11)
2.找到exe的.pas文件
三、在DLL工程源文件中添加代碼
library Mydll; uses SysUtils, //注意該單元 Classes, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} //---------------------------------------------------代碼開始 procedure ShowForm; stdcall; var Form1:TForm1; begin Form1 := TForm1.Create(nil); Form1.ShowModal; FreeAndNil(Form1); end; exports ShowForm; //定義出口函數 //----------------------------------------------------代碼結束 begin end.
四、在主窗體中調用DLL
//++++++++++++++++++++++++++++++++++++++++++++++ // 主程序調用 //+++++++++++++++++++++++++++++++++++++++++++++++ unit Unit2; interface uses type var Form2: TForm2; procedure ShowForm; stdcall; external 'Mydll.dll'; //調用mydll.dll implementation {$R *.dfm}