delphifiremonkeyrad-studiolivebindings

Custom TListBoxItem Live Bindings Advice


This might be a bit long-winded but basically I'm looking for some pointers for developing a new project.

I am using RAD Studio 11, using both Delphi and C++ Builder, although I have more experience in C++.

Previously I have been downloading data from a JSON API, processing the JSON into separate objects (mainly just containing strings), adding those objects to a TList and displaying them using a custom TListBoxItem object in a TListBox. This works fine but is slow to process, save, load, filter and display (i.e. need to create a new TListBoxItem for each object and populate manually, and save/load from a custom text file format). For future projects I would like to use something like a TClientDataSet or TFDMemTable but don't have much experience with them.

I have gotten to the point where I can populate a TFDMemTable with arbitrary JSON downloaded from my API and displaying that using design time LiveBindings on a TStringGrid.

My query boils down to how I would display my data using a TListBox with much more information than the default TListBoxItem can show (i.e. more than two strings, multiple icons/pictures, etc.), or if there is another better/easier way to handle this.

Would I create my custom TListBoxItem object and bind it programmatically somehow? Use a style book to create a custom layout? Some other process I'm not aware of?

I don't have much experience with the database objects in RAD Studio or the live bindings but this seems like the way to go to make my applications snappier and quicker for users. Any pointers would be much appreciated.


Solution

  • Assuming you are using the FMX framework (according to the tags).

    It is advised not to use TListBox with LiveBindings for creating a large number of items from a data source due to the component's slowness. The TListBox is mostly suitable for a small number of items created and customized manually (on either design-time or run-time), with each item having its own image and texts. It is also possible, if you want, to create your own custom TListBoxItem component with additional properties and elements.

    But on the other hand, there is the FMX TListView component which is optimized for large items creation and scrolling from a data source (any dataset : TClientDataSet, TFDMemTable, ...) through LiveBindings. And it has the ability you are looking for : It lets you change the conception and the appearance of TListViewItem easily in the IDE designer, by adding text and image components with custom position and settings, without the need to develop your own custom component. You can also bind those additional components to a dataset.

    Here are some useful links from Delphi documentation about how to populate a TListView through LiveBindings, and how to customize TListView appearance :