views:

215

answers:

2

I'm struggling to insert data into a TdxMemData which is linked to a grid by a TDataSourse. The MemData -called PurchaseData- has 3 columns: Date (date), Place (string) and Value (currency). I have a button that does the following:

PurchaseData->Insert();
PurchaseData->FieldByName("Date")->Value = TDateTime::CurrentDate().DateString();
PurchaseData->FieldByName("Place")->Value = "";
PurchaseData->FieldByName("Value")->Value = 0.0f;
PurchaseData->Post();

Clicked once, it inserts a row normally and the data appears in a new row of the grid, but when clicking the button again I get a popup on the Insert() saying "Could not convert variant of type (Null) into type (String)".

I'm worried about the fact that the property "KeyFields" of the columns shows in its combo the field "RecId" besides the other 3 fields. I don't remember creating any column called RecId and if I did, I removed it. I can't figure out what it is and could not find help neither.

A: 

im not in a place to test this right now but changing it to this might work

PurPurchaseData->FieldByName("Place")->Value = String("");

if that doesnt work you it will be in the way you have set up your columns.

Jonathan D
Neither String nor AnsiString worked /: Thanks for trying !
Gabriel
A: 

I had mapped the event OnSelectionChanged of the grid and read the data in the newly selected row. Unfortunately when PurchaseData->Insert() is called, the SelectionChanged event is fired right away. before the new row's data is set by the next lines. I got Null from the data read and did Bad Things with it like setting an edit->Text with it, thus the message in the popup.

Gabriel