一、新建一个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}
转载于:https://blog.51cto.com/im9527/1266890