1.定义窗体
unit UDllForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDllForm = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DllForm: TDllForm;
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
procedure ShowDllForm;stdcall;
implementation
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
begin
Application.handle:=parent;
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.ParentWindow:=Parent;//将容器设置为父窗口
DllForm.Show;
end;
procedure ShowDllForm;stdcall;
begin
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.Show;
end;
{$R *.dfm}
procedure TDllForm.btn1Click(Sender: TObject);
begin
ShowMessage('HELLO');
end;
end.
2.定义dll
library Formindll;
uses
SysUtils,
Classes,
UDllForm in 'UDllForm.pas' {DllForm};
{$R *.res}
exports
ShowDllFormInPanel,
ShowDllForm;
begin
end.3.dll窗体调用
注意:dll窗体不能直接放在父窗体里面 ,这里可以使用panel作为父窗体 对应过程ShowDllFormInPanel
dll窗体不放在父窗体 则直接使用ShowDllForm 过程,想一个对话框的形式
unit Unit1;
interface
uses
SysUtils,Classes,Forms,Windows,Messages, Controls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
pnl1: TPanel;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ShowDllFormInPanel(Parent:THandle);stdcall; external 'E:\test7\formindll.dll';
procedure ShowDllForm; stdcall; external 'E:\test7\formindll.dll';
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
ShowDllFormInPanel(pnl1.Handle);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
ShowDllForm;
end;
end.
本文详细介绍了如何在Delphi中利用DLL窗体进行跨进程通信,通过定义窗体、调用DLL函数以及在不同组件间交互来实现功能。包括DLL窗体的创建、调用ShowDllFormInPanel和ShowDllForm过程,以及如何将窗体置于容器内或直接显示。示例代码展示了具体实现步骤。
3632

被折叠的 条评论
为什么被折叠?



