如果我有TFunc<T: class>
该类型的变量,则允许我直接取消引用类成员。
即使班级完成也支持它。
但是,如果我有一个TFunc<T>
的数组,那么这不会编译
为什么不呢?这是编译器错误还是有一些潜在原因?
program Project33;
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
TTestObject = class(TInterfacedObject, IInterface)
procedure Test;
end;
procedure TTestObject.Test;
begin
WriteLn('Test');
end;
procedure Test;
var
A: IInterface;
TestObject: array [0..4] of TFunc<TTestObject>;
SingleObject: TFunc<TTestObject>;
i: integer;
begin
for i:= 0 to 4 do begin
a:= TTestObject.Create;
TestObject[i]:= function: TTestObject
begin
Result:= a as TTestObject;
end;
TestObject[i].Test; //<<-- does not compile
SingleObject:= TestObject[i];
SingleObject.Test; // <<-- works.
end;
end;
begin
Test; ReadLn;
end.