如何delphi动态调用封装在dll里的窗体

 我来答
px...0@sina.com
2016-12-20 · 超过197用户采纳过TA的回答
知道小有建树答主
回答量:544
采纳率:0%
帮助的人:306万
展开全部
以下是我编写的示例代码,完成这个示例,需要三个文件:
1. dll工程文件, test.dll:
library testDll;
uses
SysUtils,
Classes,
Forms,
FormDll in 'FormDll.pas' {frmDll};
{$R *.RES}
function GetDllForm: TForm; stdcall; export;
begin
Result := frmDll;
end;
exports
GetDllForm;
begin
end.
2. dll中包含的窗体,窗体有一个按钮,FormDll.pas:
unit FormDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TfrmDll = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmDll: TfrmDll;
implementation
{$R *.dfm}
procedure TfrmDll.Button1Click(Sender: TObject);
begin
MessageDlg('你已经成功使用了DLL窗体。', mtInformation, [mbOK], 0);
end;
initialization
begin
frmDll := TfrmDll.Create(Application);
end;
finalization
begin
frmDll.Free;
end;
end.
3. 调用dll窗体的文件,testdll.pas:
unit testdll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
function GetDllForm: TForm;
implementation
{$R *.dfm}
function GetDllForm: TForm; external 'testdll.dll';
procedure TForm2.Button1Click(Sender: TObject);
var
AForm: TForm;
begin
AForm := GetDLLForm;
AForm.Show;
end;
end.
4. 显示结果:
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式