Lazarus

Free Pascal => Beginners => Topic started by: JLWest on January 14, 2020, 07:02:48 am

Title: [Solved] Loading a Listbox
Post by: JLWest on January 14, 2020, 07:02:48 am
I'm loading a listbox from a file.

 Header Record XXXXXXXXXXXXX
 Line 1
 Line 2
 Line 3
 Trailer Record YYYYYYYYYYYYYYYY

Is there anyway to ensure the load order.
Thanks
Title: Re: Loading a Listbox
Post by: trev on January 14, 2020, 07:19:58 am
I've loaded many ListBoxes from files, and the file content has always been loaded in sequential order from the file starting with the first line and ending with the last line. I'd be very surprised if it was otherwise.
Title: Re: Loading a Listbox
Post by: JLWest on January 14, 2020, 08:56:06 am
I would be willing to post my code.
It would have to be posted on my GDrive as the files I don't think will fit.
It's late here, will have to wait until tomarrow;
Title: Re: Loading a Listbox
Post by: lucamar on January 14, 2020, 02:30:06 pm
I have never had any problems loading items to list boxes; you just do: TheListBox.Items.LoadFromFile('MyData'); and the data appears in the list as it is. From the programmer's point of view, loading items to a list box is almost exactly the same as loading lines to a memo, or doing the same to any control's propety derived from TStrings.

However ... it's different if whatever property it is descended from TStringList (or similarly extended TStrings descendant) or if the component/control had some other property that may affect how the list is build/shown.

In the case of TListBox, it has a Sorted property that, as it name announces, makes the items in the list appear sorted; it's as if you used a TStringList to load the file, called StringList.Sort and then loaded the listbox items from that string list.

If that's what is happening the solution is easy: just make sure your listbox's Sorted property is set to False.

HTH!
Title: Re: Loading a Listbox(Solved)
Post by: JLWest on January 14, 2020, 07:17:35 pm
Listbox Sort was set to true.

Thank you
TinyPortal © 2005-2018