如何在TValue中转换TDateTime?
我看到了一些方法,如AsInteger、AsDouble等,但是对于TDateTime却没有。
var
c : TRttiContext;
t : TRttiType;
f : TRttiField;
fieldValue : TValue;
fieldDateValue : TDateTime;
begin
c := TRttiContext.Create;
t := c.GetType(Self.ClassType);
for f in t.GetFields do begin
fieldValue := field.GetValue(Self);
//convert the TValue in TDateTime
end;
end;发布于 2014-07-02 09:46:47
具体的AsXXX方法(如AsInteger)只是一些内部类型的快捷方式(还有一些是通过对特定类型的优化实现的)。但是要从TValue中获取任何类型,可以使用AsType<T>方法。
https://stackoverflow.com/questions/24527743
复制相似问题