I'm using Firemonkey in Delphi 10.2 Tokyo.
I have an HD Form with a TListBox
with its MultiSelectStyle
set to either Extended
or Default
.
I am able to select multiple items, however I can't find a way to programmatically determine which items are selected.
This code
for loop := 0 to Listbox1.Count - 1 do
if Listbox1.Selected[loop] then ; //Do Something
that I've seen variations of does not compile:
[dcc32 Error] MainApplication.pas(60): E2149 Class does not have a default property
I've been through the various properties and methods of TListBox
and I can't see a way of finding out which items are selected.
Can anyone please lend me a hand on this?
In FireMonkey, the TListBox.Selected
property is a pointer to the first selected TListBoxItem
object. It is NOT an array of boolean states like it is in VCL. You must have been looking at VCL examples, not FMX examples.
The error message is because you are trying to apply your [loop]
index to a specific TListBoxItem
object, which does not have a default
property.
Use this instead:
for loop := 0 to ListBox1.Count - 1 do
begin
if ListBox1.ListItems[loop].IsSelected then
...
end;