我遇到以下情况:
interface
type
IMyInterface = interface
[GUID]
procedure MyProcedure; stdcall;
end;
TMyOBject = class(TInterfacedObject, IMyInterface)
procedure MyProcedure; virtual; stdcall; abstract;
end;
TDerivedObject = class(TMyOBject)
procedure MyProcedure; override; stdcall;
procedure SomeOtherProcedure;
end;
implementation
uses
System.Threading;
procedure TDerivedObject.MyProcedure;
begin
//DoStuff;
end;
procedure TDerivedObject.SomeOtherProcedure;
begin
TTask.Run(MyProcedure); //Error: Run can't be called with this parameter
end;
编译器说我不能使用TTask运行MyProcedure。尝试将MyProcedure强制转换为TProc是错误的。我的问题是1)什么是MyProcedure? 2)我将如何发现MyProcedure的类型?
谢谢
答案 0 :(得分:5)
TProc
不使用stdcall
调用约定。它被声明为匿名方法类型,它使用默认的register
调用约定:
TProc = reference to procedure;
而
TMyProcedure = procedure of object; stdcall;
匿名方法与声明调用约定而不是标准Delphi register
约定的方法不兼容。不要使用stdcall
,也不要插入包装器方法或本地匿名方法,即:
procedure TDerivedObject.SomeOtherProcedure;
begin
TTask.Run(procedure begin MyProcedure; end);
end;