其实以前的资料应该很多了,我贴个 Demo 出来吧
//DLL 工程单元
library FormDLL;
uses
SysUtils,
Classes,
Forms,
DLLForm in 'DLLForm.pas' {frmDLL};
{$R *.res}
{返回一个窗体对象,这是DLL的主要功能}
function GetDllChildForm(Parent:TComponent):TfrmDLL;stdcall;
begin
Result := TfrmDLL.Create(Parent);
end;
exports
SynAPP,ShowForm;
begin
end.
//DLL 窗体单元
unit DLLForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmDLL = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDLL: TfrmDLL;
procedure SynAPP(App:THandle);stdcall;
procedure ShowForm;stdcall;
implementation
uses Math;
{$R *.dfm}
procedure SynAPP(App:THandle );stdcall;
begin
Application.Handle := App;
end;
procedure ShowForm;stdcall;
begin
try
frmDLL := TfrmDLL.Create (Application);
try
frmDLL.ShowModal;
finally
frmDLL.Free;
end;
except
on E: Exception do
MessageDlg ('Error in DLLForm: ' +
E.Message, mtError, [mbOK], 0);
end;
end;
end.
//调用 DLL 窗体程序部分代码
procedure SynAPP(App:THandle);stdcall;external 'FormDLL.dll';
procedure ShowForm;stdcall;external 'FormDLL.dll';
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
SynApp(Application.Handle );
ShowForm ;
end;