[英]How to cast a object as TRttiType
I'm working with an ORM (Aurelius), and need to cast a object as TRttiType. 我正在使用ORM(Aurelius),并且需要将对象转换为TRttiType。
The TRttiType was obtained from TRtticontext.FindType. TRttiType是从TRtticontext.FindType获得的。
ISptModel = interface(IInterface)
['{688431B1-2895-4FE2-AD18-8A7892289956}']
end;
TCidade = class(TInterfacedObject, ISptModel)
end;
var
FObjectInstance: ISptModel;
LType := LContext.FindType('Spt.Cidade.Model.TCidade');
Manager.SaveOrUpdate(LType(FObjectInstance)); // I need something like this, but doesnt work
Manager.SaveOrUpdate(TCidade(FObjectInstance)); // This works
It has to be cast as TCidade so Aurelius can persist the object correctly. 必须将其强制转换为TCidade,以便Aurelius可以正确保留对象。
You cannot use LType
like you want to. 您不能像想要的那样使用
LType
。
You probably just need to cast the interface as a TObject
like so: 您可能只需要像这样将接口转换为
TObject
:
Manager.SaveOrUpdate(FObjectInstance as TObject);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.