0

I am developing an FMX (Android) app using a ListView in Delphi 10.2.3. I have the Listview live(bound) to a ClientDataSet with (Synch->*). This works very well, and any changes in Listview are propagated to the ClientDataSet, including the ClientDataSet's event handlers, such as BeforeUpdate, Post and AfterScroll.

Now when I move the record pointer in the ClientDataSet programmatically, the Listview does not synch with the change. It seems the Livebinding only works "one way" (from the UI to the Dataset).

How can I make the Listview follow the ClientDataSet, the way it does in the VCL when using a DataSource?

// here I expect the see the selected item start at the first item 
// in the UI in index order and move quickly down through the 
// list until it stops at the last one. This doesn't happen. The UI remains
// unaffected.
ClientModule.CDSData.First;
while not ClientModule.CDSData.Eof do
begin
   ClientModule.CDSData.Next;
   Sleep(100);
end;
Freddie Bell
  • 2,186
  • 24
  • 43
  • From what I remember it is bidirectional in that if the data set changes that change is reflected in the UI, but I am guessing a change of data set cursor position doesn't count as a change, which makes sense. You don't want the UI changing every time you are calculation something on the data set in the background. So, the obvious answer is to change the UI (ListView) programmatically instead. – Dsm Oct 05 '18 at 08:29
  • Since I posted the question, the answer came to me. The simple way to do it, is to change the `ListView1.Itemindex` programmatically (and to remember to call the `Listview1.OnChange` handler because the documentation says you have to do it yourself in this situation) – Freddie Bell Oct 05 '18 at 08:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181326/discussion-between-dsm-and-nolaspeaker). – Dsm Oct 05 '18 at 09:14
  • OK I'll delete my comments too. – Dsm Oct 05 '18 at 09:22

1 Answers1

0

The easy answer to this question is to perform a

if ClientModule.CDSData.Locate('PKID', VarArrayOf([PKIDValue]), []) then

It seems that while moving the record pointer using CDSData.Next doesn't sync back to the Live(Bound) Listview, using a locate does.

Freddie Bell
  • 2,186
  • 24
  • 43