I have a bunch of different methods for creating, calling and setting properties of different objects using Delphi's RTTI. But now I have come to an error where setting a TDateTime
triggers an error like: "Cannot convert variant into double". Google doesn't help when searching for this error.
So far, I'm defining an object of any type, for example:
TExample = class
private
FDateField : TDateTime;
published
property DateField : TDateTime read FDateField write FDateField;
end;
I'm then putting this object in a TObjectList
, and then looping some internal logic that's not really relevant to the problem. But when I come to the DateField
property, it triggers the error. I'm trying to set it like this:
objPropValue := '12/02/2018 12:25:00';
objPropName := 'DateField';
if IsPublishedProp(parameterObject, objPropName) then
begin
SetPropValue(parameterObject, objPropName, objPropValue); <- doesn't work on DateField
end;
This is only a hardcoded example, the objPropValue
and Name
are set in a loop and can be of any other type. I tried different formatting as well, but I can't seem to find the correct way to do this.