1
votes

I am using Delphi 10.3.1 (Firemonkey FMX) to build android and iOS app. I have a TListView, live binding with a AdapterBindSource. My problem is: new records does not appear after Adapter refreshed.

==============

  1. I created a TObjectList, added 3 objects to it
  2. I created a TBindSourceAdapter by passing a TObjectList to create it.
  3. I assign the TBindSourceAdapter to AdapterBindSource1.Adapter.
  4. Then I Free the TObjectList and re-create it, add 4 newly created objects (3 of them are old records, with some data modified, 1 is a new record)
  5. I do TBindSourceAdapter.Refresh and TAdapterBindSource.Refresh
  6. Those 3 old records are refreshed successfully with modified data displayed, but the new record is not showing up in Android and iOS
  7. The same logic working fine in Windows platform

==============

My logic

create TObjectList

first I get records from Rest Server and converted into a TObjectList

TData : class(TObject) ... // a class stored some data
TDataList = class(TObjectList<TData>)
// then I get data from Rest Server and created FList, it is a Form private variable
FList := TDataList.Create; // a private Form variable
// create Tdata objects and add to FList .....

create TBindSourceAdapter, assign to AdapterBindSource

    var ABindSourceAdapter: TBindSourceAdapter;
// ....
    ABindSourceAdapter := TListBindSourceAdapter<TData>.Create(self, FList, True);
    AdapterBindSource1.Adapter := ABindSourceAdapter;
    AdapterBindSource1.Active := true;

then the records show on ListView which live bindings with the AdapterBindSource

Refresh FList records

When click on Refresh button, I trigger to get data from Rest server again, I do free the FList and re-create it

FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.

refresh the Adapter

then I refresh the adapter

    AdapterBindSource1.Adapter.Refresh;
    AdapterBindSource1.Refresh;

here the 3 old records are refreshed successfully, modified data are displayed correctly, however, new record is not showing, the TListView still showing 3 records only.

Notes:

  1. I did not re-create TListBindSourceAdapter and assign to AdapterBindSource1.Adapter again during refresh, the records still refreshed successfully.
  2. However, even I re-create TListBindSourceAdapter and assign to AdapterBindSource1.Adapter again, new record still does not show up, only caused memory leaking.

How can I resolve this? is there something I missing like to refresh the TListView? Or my BindSourceAdapter refresh logic is wrong?

Thanks for any help.

1

1 Answers

1
votes

I found a solution to refresh the TListView.

The issue happened due to re-create of TObjectList here:

FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.

Free the List and re-create caused the issue. I changed it to clear the list and add new objects to it.

FList.Clear();
// then add objects to it again, such as FList.AddRange(...)

then AdapterBindSource refreshed successfully.

If the TObjectList free and re-created, it no more used by the Adapter correctly.