有没有一些技巧如何获得成员函数的指针在Lazarus/delphi中? 我有这样的代码将不能编译....
错误是 德尔福:
variable required
在拉撒路 :
Error: Incompatible types: got "<procedure variable type of function(Byte):LongInt of object;StdCall>" expected "Pointer"
获取成员函数的指针delphi
代码:
TClassA = class
public
function ImportantFunc(AParameter: byte): integer; stdcall;
end;
TClassB = class
public
ObjectA: TClassA;
ImportantPtr: pointer;
procedure WorkerFunc;
end;
function TClassA.ImportantFunc(AParameter: byte): integer; stdcall;
begin
// some important stuff
end;
procedure TClassB.WorkerFunc;
begin
ImportantPtr := @ObjectA.ImportantFunc; // <-- ERROR HERE
end;
谢谢!
为什么它是不可能的?他可以将方法定义为'class'方法并将'TMethod.Code'指针作为回调函数传递?或不? – teran
@大卫:你是对的。我想用它作为回调。但'TClassA'实际上是一个'TCollectionItem'(!)所以每个项目都必须有自己的窗口回调:(因此不可能在全局范围内定义它。这太可怕了,但我不能相信这是不可能的。 – Peter
@teran必须是静态的,而不是类方法 –