Forum > LCL
Is there a bug in TListBox?
vfclists:
This code is to scan the list of selected items in a List box and add them to a string list. It crashes when it gets to an unselected item.
Am I doing something wrong here, or is it a known bug?
--- Code: ---procedure TutilitiesInterfaceForm.GetEventsList(list: TStringList);
var
i :integer;
begin
for i := 0 to lbEventsToMonitorA.Items.Count - 1 do
begin
if lbEventsToMonitorA.Selected[i] = true then
list.Add(lbEventsToMonitorA.Items[i]);
end;
end;
--- End code ---
Marc:
on what line does it crash ?
This code should work.
ps.
--- Code: ---if lbEventsToMonitorA.Selected[i] = true then
--- End code ---
is the same as
--- Code: ---if lbEventsToMonitorA.Selected[i] then
--- End code ---
Selected[] already returns a boolean, no need to compare it against another boolean
vfclists:
It crashes on this line:
--- Code: ---if lbEventsToMonitorA.Selected[i] = true then
--- End code ---
and the crash occurs when the item is not selected, ie always crashes on the first on selected item.
--- Quote from: Marc on May 03, 2010, 11:56:05 pm ---on what line does it crash ?
This code should work.
ps.
--- Code: ---if lbEventsToMonitorA.Selected[i] = true then
--- End code ---
is the same as
--- Code: ---if lbEventsToMonitorA.Selected[i] then
--- End code ---
Selected[] already returns a boolean, no need to compare it against another boolean
--- End quote ---
eny:
Just a thought: is your listbox populated, the first time you call 'GetEventsList'?
Marc:
--- Quote from: eny on May 04, 2010, 06:46:43 am ---Just a thought: is your listbox populated, the first time you call 'GetEventsList'?
--- End quote ---
if not populated, "for i := 0 to lbEventsToMonitorA.Items.Count - 1 do" wont do anything.
Navigation
[0] Message Index
[#] Next page