简体   繁体   English

如何在Borland Builder中将数据插入TdxMemData

[英]How to insert data into a TdxMemData in Borland Builder

I'm struggling to insert data into a TdxMemData which is linked to a grid by a TDataSourse. 我正在努力将数据插入通过TDataSourse链接到网格的TdxMemData中。 The MemData -called PurchaseData- has 3 columns: Date (date), Place (string) and Value (currency). MemData(称为PurchaseData)具有3列:日期(日期),位置(字符串)和值(货币)。 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)". 单击一次,它将正常插入一行,并且数据显示在网格的新行中,但是再次单击该按钮时,我在Insert()上弹出一个窗口,说“无法将类型(Null)的变量转换为类型(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. 我担心以下事实:列的属性“ KeyFields”在其组合中显示了除其他3个字段之外的字段“ RecId”。 I don't remember creating any column called RecId and if I did, I removed it. 我不记得创建任何名为RecId的列,如果这样做,则将其删除。 I can't figure out what it is and could not find help neither. 我不知道这是什么,也找不到帮助。

im not in a place to test this right now but changing it to this might work 我暂时无法测试此位置,但将其更改为此可能有效

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

if that doesnt work you it will be in the way you have set up your columns. 如果那不起作用,那将是您设置列的方式。

I had mapped the event OnSelectionChanged of the grid and read the data in the newly selected row. 我已经映射了网格的OnSelectionChanged事件,并读取了新选择的行中的数据。 Unfortunately when PurchaseData->Insert() is called, the SelectionChanged event is fired right away. 不幸的是,当调用PurchaseData-> Insert()时,立即触发SelectionChanged事件。 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. 我从读取的数据中获取了Null并对其进行了“坏事”,例如设置了edit-> Text,从而在弹出窗口中看到了消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM