ListCollections is a sample application on how to use LiveBindings to populate a list box with the items gathered from various collections.
You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repository according to your RAD Studio version.
ListCollections Sample requires the following component:
TBindingsList: Built on the TCustomBindingsList component and publishes additional properties that can be accessed from within the Object Inspector.
TBindScope: Non-visual component that provides a way to make data contained by the specified component available to all components that want to access it, using LiveBindings.
The sample application uses several visual objects that are bound via TBindList to the list box. A combo box holds a series of items describing various collections described in SampleCollections.pas you can choose from when populating the list box.
The SampleCollections.pas unit implements the additionally supported collections of elements that will be exported to the List Box by means of LiveBindings. The sample used a class Factory Design Pattern to dynamically build several different types of collections:
A list of objects
A list of generics
A list of strings
The Control Component and Control Expression fields are not editable and they specify the control component (ListBox1) and the control expression.
The Source Component field is also not editable and it specifies the source component, which varies each time you select another collection type from the combo box.
The Source Expression field is editable and allows typing in the binding expression used to gather information from the source component. This binding expression also supports conversion methods such as ToStr to convert from numbers to strings.
On Changing the ComboBox the selected data object is assigned to TBindScope instance data object to make available to all components that wants to access it.
Each time you press the Fill button (or AutoFill is selected), the list box is populated with 100 items, generated at run time, for the collection specified through the Collection combo box. Check out the full article in the DocWiki about the FMX.ListCollections sample.
The FMX.ListCollections sample is not appropriate for beginners (advanced knowledge is required; to read the code, you should know RTTI, and advanced language elements such as anonymous methods and Design Patterns).
Check out the full source code for the ListCollections projects for Delphi and C++Builder over on GitHub.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition