Delphi XE2 RTTI坏了? [英] Delphi XE2 RTTI broken?
问题描述
我发现一个类中的TBytes变量的RTTI信息从不生成。
以下代码在D2010中运行良好,但显示消息XE2 / XE3中的错误
有没有人有任何线索?这将完全打破我们所有的软件数据序列化实现
要测试代码,请将Rtti单元添加到使用声明中
type
TMyClass = class
public
Field1:Integer;
Field2:TBytes;
结束
程序TForm2.Button1Click(发件人:TObject);
var
i:整数;
数据:TMyClass;
Rtti:TRttiContext;
RttiClassType:TRttiInstanceType;
begin
数据:= TMyClass.Create;
try
//获取上下文
Rtti:= TRttiContext.Create;
try
//获取类的类型
RttiClassType:= TRttiInstanceType(Rtti.GetType(Data.ClassInfo));
//检查字段
for i:= 0 to High(RttiClassType.GetFields)do
begin
//检查字段类型
如果没有分配(RttiClassType.GetFields [i] .FieldType)然后
ShowMessage('Error');
end;
finally
Rtti.Free;
结束
finally
Data.Free;
结束
end;
当检查Field2是一个TBytes时会显示错误信息,因为FieldType总是为零! !!有没有人对D2010做XE2的RTTI发生什么变化有任何线索吗?
可能是因为TBytes类型从Byte数组更改为通用数组?
这是在XE3中修复的已知问题。不幸的是,升级是获得修复的唯一方法;错误修复通常不会被移回。
编辑:或不。显然,这并不是固定的,因为它仍然发生在XE3中。报告为新的案例,并提及103729可能是最好的行动方案。
I recently migrated from D2010 to DXE2 and found a showstopper bug (Or feature?) in XE2 and XE3 (Tested in my friend XE3) related to RTTI generation for TBytes fields inside classes.
I found that the RTTI information for a TBytes variable inside a class is never generated.
The following code works well in D2010, but shows the message "Error" in XE2/XE3
Does anyone have any clue? This will totally break all our software data serialization implementation
To test the code please add Rtti unit to the uses declaration
type
TMyClass = class
public
Field1: Integer;
Field2: TBytes;
end;
procedure TForm2.Button1Click(Sender: TObject);
var
i: Integer;
Data: TMyClass;
Rtti: TRttiContext;
RttiClassType: TRttiInstanceType;
begin
Data := TMyClass.Create;
try
// Get the context
Rtti := TRttiContext.Create;
try
// Get the type for the class
RttiClassType := TRttiInstanceType(Rtti.GetType(Data.ClassInfo));
// Check the fields
for i := 0 to High(RttiClassType.GetFields) do
begin
// Check the field type
if not Assigned(RttiClassType.GetFields[i].FieldType) then
ShowMessage('Error');
end;
finally
Rtti.Free;
end;
finally
Data.Free;
end;
end;
The error message will be displayed when checking for Field2 that is a TBytes becayse the FieldType is always nil!!!
Does anyone has any clue of what have changed in the RTTI from D2010 do XE2? Maybe because the TBytes type was changed from array of Byte to the generic array?
This is a known issue that was fixed in XE3. Unfortunately, upgrading is the only way to get a fix for it; bug fixes don't usually get ported back.
EDIT: Or not. Apparently this is not actually fixed, as it still occurs in XE3. Reporting it as a new case and mentioning 103729 would probably be the best course of action.
这篇关于Delphi XE2 RTTI坏了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!