delphi调用带有窗体的dll,窗体的事件怎样调用?
应该在程序中怎样使DLL的窗体事件运行? 展开
推荐于2017-12-15 · 知道合伙人软件行家
以下是我编写的示例代码,完成这个笑梁祥示例,需要三个文件:
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. 显示结果:
给你派雹顷个例程
dll中声明导尘陆出的函数
procedure ShowDllForm;stdcall;
begin
if Form1 = nil then
begin
Form1 := TForm1.Create(Application);
Form1.Show;
end else if not Form1.Showing then
Form1.Show;
end;
晕,这图不就是一个buttonclick的事件吗?我就是在应用程序里按下的时候出错了..怎样调用这个按钮的点击事件(我感觉应该不用调用该事件,但不知道是不是).
根据你上面说的DLL只能有过程和函数?窗体按钮的事件都不能调用吗?
我汗,使用dll中的窗口,只需要导出窗口就行了,里面的事件是由它自身维护的,