Alb*_*tti 2 delphi reflection tdatetime tvalue
如何在 TDateTime 中转换 TValue?
我看到有 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;
Run Code Online (Sandbox Code Playgroud)
具体AsXXX
方法(如AsInteger
)只是一些内在类型的快捷方式(有些还通过针对特定类型的优化来实现)。但是要从 a 获取任何类型,TValue
您可以使用该AsType<T>
方法。