Delphi XE中的类型转换问题

V.K*_*pov 2 delphi delphi-7 delphi-xe

我尝试用这种方式列出程序:

type

TProc = procedure of object;

TMyClass=class
private
fList:Tlist;
function getItem(index:integer):TProc;
{....}
public
{....}
end;
implementation
{....}
function TMyClass.getItem(index: Integer): TProc;
begin
 Result:= TProc(flist[index]);// <--- error is here!
end;
{....}
end.
Run Code Online (Sandbox Code Playgroud)

并得到错误:

E2089无效的类型转换

我该如何解决?正如我所看到的,我可以制作一个只有一个属性的假类Proc:TProc;并列出它.但我觉得这是一个糟糕的方式,不是吗?

PS:项目必须与delphi-7兼容.

Ser*_*yuz 5

类型转换是无效的,因为你不能使方法指针适合指针,方法指针实际上是两个指针,首先是方法的地址,第二个是对方法所属对象的引用.请参阅文档中的过程类型.这不适用于任何版本的Delphi.