Ric*_*ler 3 delphi generics rtti typeinfo delphi-2010
我正在尝试使用RTTI的通用记录,但遇到类型信息的问题.有谁知道为什么以下不能使用Delphi 2010进行编译?
program GenericTypeInfo;
{$APPTYPE CONSOLE}
uses
TypInfo,
SysUtils;
type
TMyRec<T> = record
public
Value: T;
end;
TMyInt = TMyRec<Integer>;
TMyString = TMyRec<String>;
begin
try
Writeln(GetTypeName(TypeInfo(TMyRec<Integer>))); <--- This works fine
Writeln(GetTypeName(TypeInfo(TMyRec<String>))); <--- so does this
Writeln(GetTypeName(TypeInfo(TMyInt))); <--- BUT this won't compile
Writeln(GetTypeName(TypeInfo(TMyString))); <--- nor this!!
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
Run Code Online (Sandbox Code Playgroud)
上面指出的行会生成以下编译器错误:
[DCC Error] GenericTypeInfo.dpr(24): E2134 Type 'TMyInt' has no type info
[DCC Error] GenericTypeInfo.dpr(24): E2134 Type 'TMyString' has no type info
Run Code Online (Sandbox Code Playgroud)
我不能说2之间的最大区别是什么?我承认我不是一个低级别的专家,但为什么编译器会以不同的方式对待它?我需要它来为TMyInt和TMyString类型工作.
谢谢你的帮助.
| 归档时间: |
|
| 查看次数: |
3229 次 |
| 最近记录: |