dll form in pagecontrol[未经测试]

33次阅读
没有评论

Kod (Delphi):
The DLL:

library Project1;

uses
SysUtils,
Classes, Forms,
Unit1 in ‘Unit1.pas’ {Form1};

{$R *.res}

function GetFormClass: TFormClass;
begin
Result := TForm1;
end;

exports GetFormClass;

begin
end.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons, ComCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add(‘testing’);
end;

end.

The Main Application:

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;

type
TFormMain = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
procedure FormCreate(Sender: TObject);
private
DLLForm: TForm;
{ Private declarations }
public
{ Public declarations }
end;

var
FormMain: TFormMain;

implementation

{$R *.dfm}

type
TGetFormClass = function: TFormClass;

const
GetFormClassName = ‘GetFormClass’;

procedure TFormMain.FormCreate(Sender: TObject);
var
DLL: THandle;
DLLFormClass: TFormClass;
GetClass: TGetFormClass;
TabSheet: TTabSheet;

begin
DLL := LoadLibrary(‘Project1.DLL’);
if DLL > HINSTANCE_ERROR then
begin
GetClass := GetProcAddress(DLL, GetFormClassName);
if assigned(GetClass) then
begin
DLLFormClass := GetClass;
TabSheet := TTabSheet.Create(PageControl1);
TabSheet.PageControl := PageControl1;
DLLForm := DLLFormClass.Create(Application);
DLLForm.Parent := TabSheet;
DLLForm.Top := 0;
DLLForm.Left := 0;
DLLForm.Show;
end;
end;
end;

end.
转自http://www.delphidunyasi.com/threads/dll-form-in-pagecontrol.11339/

正文完