I built a multi-device app using FireMonkey.
I have a ListView Live-Binding 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);
begin
(AEditor.CurrentObject as TListItem).Tag :=
DB_Table.FieldByName('DBID').AsInteger;
end;
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);
begin
ListView1.BeginUpdate;
BindSourceDB1.DataSource.DataSet.close;
//or LinkListControlToField1.Active:=false;
ListView1.EndUpdate;
end;
On either case, it will produce 'Argument out of range' error. What is the way to do this simple task?