Recent

Author Topic: Loop over select items in listbox?  (Read 5370 times)

Trenatos

  • Hero Member
  • *****
  • Posts: 537
    • MarcusFernstrom.com
Loop over select items in listbox?
« on: March 20, 2013, 10:26:37 pm »
Greetings!

I'm new to Lazarus and Pascal. (Though not to programming in general.)
I'm trying to figure out how to loop over selected items in a listbox with multiple selects.

I can pick single items but I can't figure out how to loop over the list.
The purpose will be to save the output to a database, but for testing I'm just trying to populate a second, empty listbox.

I've tried a bunch of things but I'm grasping in the dark, so I figured it's time to ask for help.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Loop over select items in listbox?
« Reply #1 on: March 20, 2013, 10:48:12 pm »
Hi,
this writes out all selected items:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var i: Integer;
begin
  for i:=0 to ListBox1.Items.Count-1 do
    if ListBox1.Selected[i] then writeln(ListBox1.Items[i]);
end;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Trenatos

  • Hero Member
  • *****
  • Posts: 537
    • MarcusFernstrom.com
Re: Loop over select items in listbox?
« Reply #2 on: March 20, 2013, 11:16:14 pm »
Thank's Blaazen, it works perfectly.

ted

  • Newbie
  • Posts: 5
Re: Loop over select items in listbox?
« Reply #3 on: May 27, 2013, 09:25:33 am »
thank you Blaazen.
Just what I needed !

 

TinyPortal © 2005-2018