How can I convert a TValue in TDateTime?
I see there are methods like AsInteger, AsDouble, etc. but nothing for 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;
The concrete
AsXXX
methods (likeAsInteger
) are just shortcuts to some intrinsic types (and some are also implemented with optimizations for the specific type). But to get any type from aTValue
you can use theAsType<T>
method.