5
52253831
Unregistered / Unconfirmed
GUEST, unregistred user!
[red]一个EXE调用DLL,DLL要在EXE的FORM中创建几个Panel对象,然后对点击Panel对象的事件做出反应。[/red]
[red]我写的代码能响应事件但ButtonRClick里为何Sender是空[/red]
代码如下:
DLL单元
library Demo;
uses
SysUtils
, Classes
, ExtCtrls
, Controls
, Graphics
;
{$R *.res}
Var
rButton : array of TPanel;
xProc :TNotifyEvent;
function iif(Condition: Boolean; TrueReturn:Variant; FalseReturn: Variant): Variant;
begin
if Condition then Result := TrueReturn else Result := FalseReturn;
end;
procedure ButtonRClick(Sender: TObject);
var
i :integer;
begin [red][h1]//问题在这里为何事件是响应了但这里Sender为何是Nil[/h1][/red]
TPanel(Sender).Tag :=iif(TPanel(Sender).tag=0,1,0);
TPanel(Sender).BevelOuter:=iif(TPanel(Sender).tag=1,bvRaised,bvLowered);
TPanel(Sender).Color :=iif(TPanel(Sender).tag=1,clBtnFace,clTeal);
end;
procedure xxxxx(vPanelointer);stdcall;export;
Var
X,Y,Nu,ID :integer;
xPanel :TPanel;
begin
xPanel:=vPanel;
SetLength(rButton,33);
Nu:=(xPanel.Width) div 21 ;
X :=5;
Y :=5;
for ID:=0 to 32 do
begin
rButton[ID] :=TPanel.Create(xPanel);
rButton[ID].Tag :=1;
rButton[ID].Caption:=iif((ID+1)<10,'0','') + inttostr(id+1);
rButton[ID].top :=Y;
rButton[ID].Left :=X;
rButton[ID].Height :=20;
rButton[ID].Width :=20;
rButton[ID].Parent :=xPanel;
@xProc:=Pointer(@ButtonRClick);
rButton[ID].OnClick:=xProc; //TNotifyEvent(@MyMet);
X:=iif(((ID+1) mod NU)=0, 5 ,X+21);
Y:=iif(((ID+1) mod NU)=0, Y+21,y);
end;
end;
exports
xxxxx name 'demo';
begin
end.
EXE单元
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
{插件接口函数定义}
InitShow =procedure(xPanel:TPanel) ;stdcall
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
Moudle :THandle; //插件动态链接库句柄
xShow :initShow;
begin
Moudle:=loadlibrary(pchar('demo.dll'));
xShow :=GetProcAddress(Moudle,'demo');
xShow(panel1);
end;
end.
[red]我写的代码能响应事件但ButtonRClick里为何Sender是空[/red]
代码如下:
DLL单元
library Demo;
uses
SysUtils
, Classes
, ExtCtrls
, Controls
, Graphics
;
{$R *.res}
Var
rButton : array of TPanel;
xProc :TNotifyEvent;
function iif(Condition: Boolean; TrueReturn:Variant; FalseReturn: Variant): Variant;
begin
if Condition then Result := TrueReturn else Result := FalseReturn;
end;
procedure ButtonRClick(Sender: TObject);
var
i :integer;
begin [red][h1]//问题在这里为何事件是响应了但这里Sender为何是Nil[/h1][/red]
TPanel(Sender).Tag :=iif(TPanel(Sender).tag=0,1,0);
TPanel(Sender).BevelOuter:=iif(TPanel(Sender).tag=1,bvRaised,bvLowered);
TPanel(Sender).Color :=iif(TPanel(Sender).tag=1,clBtnFace,clTeal);
end;
procedure xxxxx(vPanelointer);stdcall;export;
Var
X,Y,Nu,ID :integer;
xPanel :TPanel;
begin
xPanel:=vPanel;
SetLength(rButton,33);
Nu:=(xPanel.Width) div 21 ;
X :=5;
Y :=5;
for ID:=0 to 32 do
begin
rButton[ID] :=TPanel.Create(xPanel);
rButton[ID].Tag :=1;
rButton[ID].Caption:=iif((ID+1)<10,'0','') + inttostr(id+1);
rButton[ID].top :=Y;
rButton[ID].Left :=X;
rButton[ID].Height :=20;
rButton[ID].Width :=20;
rButton[ID].Parent :=xPanel;
@xProc:=Pointer(@ButtonRClick);
rButton[ID].OnClick:=xProc; //TNotifyEvent(@MyMet);
X:=iif(((ID+1) mod NU)=0, 5 ,X+21);
Y:=iif(((ID+1) mod NU)=0, Y+21,y);
end;
end;
exports
xxxxx name 'demo';
begin
end.
EXE单元
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
{插件接口函数定义}
InitShow =procedure(xPanel:TPanel) ;stdcall
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
Moudle :THandle; //插件动态链接库句柄
xShow :initShow;
begin
Moudle:=loadlibrary(pchar('demo.dll'));
xShow :=GetProcAddress(Moudle,'demo');
xShow(panel1);
end;
end.