(1)带窗体的动态链接库:
library Project1;
uses
SysUtils,
Classes,
Forms,
Unit1 in 'Unit1.pas' {FormDll};
{$R *.RES}
function GetDllForm: TForm;
begin
Result := FormDll;
end;
exports
GetDllForm;
begin
end.
<hr>
(2)动态链接库的窗体:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TFormDll = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
FormDll: TFormDll;
implementation
{$R *.DFM}
initialization
begin
FormDll := TFormDll.Create(Application);
end;
finalization
begin
FormDll.Free;
end;
end.
<hr>
(3)如何调用:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function GetDllForm: TForm;
implementation
{$R *.DFM}
function GetDllForm: TForm; external 'project1.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
AForm := GetDLLForm;
ShowMessage(Format('ClientHeight=%d ClientWidth=%d', [AForm.ClientHeight, AForm.ClientWidth]));
end;
end.