我使用MethodAddress方法获得了另一个窗体中的某一过程的指针,但该过程带有一个字符串型的参数,我发现调用该过程时,这个参数出错,请问大家有知道问题出在哪里吗?代码如下:var
_Load: procedure(AText: string);
begin
@_Load := _Form.MethodAddress('Sys_HotKey'); //_Form为某一窗体
if @_Load <> nil then
_Load('123'); //传入字符串‘123’,但事实上传不过去。
end;
end;
_Load: procedure(AText: string);
begin
@_Load := _Form.MethodAddress('Sys_HotKey'); //_Form为某一窗体
if @_Load <> nil then
_Load('123'); //传入字符串‘123’,但事实上传不过去。
end;
end;
解决方案 »
- 请教一个DELPHI问题:delphi7能否连接其他电脑上的ACCESS数据库?
- TWWDBGRID保存问题!
- 多层开发如何从服务端断开某个用户的连接?
- 使用SOAP怎样在客户端判断已经连接到服务端(服务端可用)(WEB SERVER+SOAP)
- 如何判断Socket是不是断了?
- 求助一个关于类似于QQ的好友列表的控件!!!
- 如何获得ACTIVEXFORM中各控件、事件?(十万火急!!!)
- Access 编程出错!急!
- 已知圆点坐标和半径,想用这个半径做一次圆周运动。类似圆形雷达扫描线
- 招兼职delphi程序员
- DelphiDistiller.exe 运行出错 等达人牛人神人.....
- 新手发帖 DELPHI +BDE +DBF库 关于SQL语法的问题
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
published
procedure test(str: string);
{ Public declarations }
end;procedure TForm1.test(str: string);
begin
ShowMessage(str);
end;procedure TForm1.Button1Click(Sender: TObject);
type
Test = procedure(AObj : TObject; str: string);
var
TAddress: Pointer;
T1: Test;
begin
TAddress := Form1.MethodAddress('test');
T1 := Test(TAddress);
T1(nil, '123');
end;
procedure test(str: pointer);
其他参数定义成指针就可以了
// unit1unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation{$R *.dfm}uses unit2;type
TExec = procedure(str: string) of object;procedure TForm1.Button3Click(Sender: TObject);
var
R: TMethod;
Exec: TExec;
begin
R.Data := Pointer(Form2);
R.Code := Form2.MethodAddress('ss') ;
if NOT Assigned(R.Code) then
begin
showmessage('exit');
exit;
end;
Exec := TExec(R);
Exec('abc');
end;end.// unit2unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Button1: TButton;
procedure ss(str: string);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.ss(str: string);
begin
showmessage(str);
end;end.