How to delete a database record linked to a listview item?


I built a multi-device app using FireMonkey.
I have a ListView Live-Binded to a DB. Both synched by *.
It all works normally until I left wipe an item to delete. The item can be deleted, but the DB record is not.
So following Doug Rudd advice, implemented following code to store DBID and locate the deleting Item.
procedure TPassPlus.LinkListControlToField1FilledListItem(Sender: TObject;
const AEditor: IBindListEditorItem);
(AEditor.CurrentObject as TListItem).Tag :=

myDBID:= ListView1.Selected.Tag.ToString;
if DB_Table.Locate(‘DBID’,myDBID,[]) then DB_Table.delete;

It worked well to delete the DB record. However, when ListView1DeletingItem event finished, it generated a ‘Argument out of range’ error, which can be traced into TPresentedListView.DoDeleteItem event. It looks like, when DB record deleted, Listview has deleted the correspoding item, so when ListView1DeletingItem event finished, ListView has nothing to delete. What is the solution?
I was trying to decouple the link between the DB and Listview at runtime so I can delete the record and re-link the two.
I tried following code as a test.
procedure TPassPlus.ListView1DeletingItem(Sender: TObject; AIndex: Integer;
var ACanDelete: Boolean);
//or LinkListControlToField1.Active:=false;

On either case, it will produce ‘Argument out of range’ error.
I think LiveBinding suppose to bridge UI and Dataset, Deleting an item of Listview natually should delete the bound data record. If not, what is the point of using LiveBinding? No wonder so many negative comments on LiveBiding. It cannot implement some basic UI-Data binding function.
Correct me if I am wrong.

Comments are closed.