I have a following firebird dataset:
ds1 : TpFIBDataset;
DFM file:
object ds1ID: TFIBIntegerField
FieldName = 'ID'
end
object ds1FIELD_VALUE: TFIBStringField
FieldName = 'FIELD_VALUE'
Size = 250
end
In my Firebird database: ID is integer field and FIELD_VALUE is varchar field.
Delphi 7: Data is being inserted like this
ds1.InsertRecord([123, anyValue]);
here anyValue : variant;
If anyValue = null, null is getting inserted into the database which is the required functionality.
In Delphi XE4, I am doing same like this:
ds1.Insert;
ds1.FieldByName('ID').AsInteger := 123;
ds1.FieldByName('FIELD_VALUE').AsString := anyValue;
ds1.Post;
I get error: could not convert variant of type (null) into type (OleStr)
When I try like this
ds1.Insert;
ds1.FieldByName('ID').AsInteger := 123;
ds1.FieldByName('FIELD_VALUE').AsString := VarToStr(anyValue);
ds1.Post;
Empty string is inserted into the database, but I need null there. What and where should I make change to accomplish this task.
AsStringbut useValuethen. Or if thatTpFIBDatasetsupports some setting which converts empty string toNULL, use that and try to keepAsStringcasting.ds1.InsertRecord([123, anyValue]);. You don't do that in the XE4 code.ds1.FieldByName('FIELD_VALUE').Clearwill set the value toNULL, I think