Tang
Members-
Content Count
4 -
Joined
-
Last visited
Community Reputation
1 NeutralRecent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
ListView1DeletingItem already deleted the Listview.item[AIndex]. then it comes to ListView1DeleteItem so, here AIndex is always 0, ( guess being reset after the ListItem was deleted). So, we need to get the DB id associated with the ListItem in ListView1DeletingItem event. In this event, we still have the Item and its Tag ...
-
I think that is the Pro and Con for LiveBinding. It is easy to use but with bugs or big improvement space. It handles the link, update, delete, index etc between Listview and the datasource. We cannot do any change, otherwise it will mess up the relationships between the 2 easily. ListView1DeleteItem event is the place where we can 'change' work. But occasionally, I will have 'access violation error'. I am still not figuring out when and why, error not reproducible.
-
Thanks Serge, Indeed, it worked for me as well. It means ListView1DeletingItem is only for retrieving the DB record 'id' which is bound to the deleting ListView.Items[AIndex] and ListView1DeleteItem is for DB delete work. For my case, when I delete the DB record, my ListView has no data to show. So, I have to close and reopen the DB to let the ListView to show the data. Not sure if you had similar issue. The whole point of this question is to find a way , when user delete a Listview item, it will also safely delete the livebinding DB record. I thought this is very straight forward operation. In fact, Item.delete is not linked to DB record deleting automatically. I guess this is about LinkListControlToField1. This is a one way binding, not bi-directional. So. cause the trouble. And in ListView1DeletingItem event, we cannot do any deletion, it will cause many different kinds of error because the ListView index and DB record index. If you have a search box working, things will get more complicated. Here, we can only get a DBID related to the deleting Item. then in ListView1DeleteItem event do the DB.delete. It seems working now, thanks for all your helps. I did not have a 'access violation' ! error when delete the last record. But I did see some posts mentioned similar issue. Maybe need BeginUpdate/EndUpdate? 'wipe-left' is quite handy for deletion. For instance, on iOS Notification Page, you will receive many notifications from various APPs. They can be wiped off. Email App uses this to delete email. But I guess Serge's delete button seems not a native FMX ListView delete button. Did you added by your own? That may cause the ‘access error’. You can only wipe one item therefore, only 1 button will be shown. Yours shows all the buttons. My APP's Listview is here. It works on windows and mobile OS consistently.
-
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?