I recently changed my code to directly use a DataSet query to load values to a class because it is faster than using TObjectManager and I needed more performance. Talking about an object list of many thousands of items.
But now when I try to assign a null value to a Nullable property I get an exception.
Example:
TMyClass = class
myproperty1: Nullable;
myproperty2: Nullable;
myproperty3: Nullable;
end;
and trying this gives me the exception:
myClass.myproperty1 := myDataSet.FindField('somefield').AsVariant;
myClass.myproperty2 := myDataSet.FindField('somefield').AsVariant;
myClass.myproperty3 := myDataSet.FindField('somefield').AsVariant;
How does TObjectManager works then?
When loading data from a dataset with TObjectManager all null values are set properly.
I managed to solve this by adding this method to the Nullable record. class operator Implicit(Value: Variant): Nullable<T>;
But I'm sure this is not the best approach.