Recent

Author Topic: [Solved] Loading a Listbox  (Read 400 times)

JLWest

  • Hero Member
  • *****
  • Posts: 625
[Solved] Loading a Listbox
« 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
« Last Edit: January 14, 2020, 07:19:33 pm by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

trev

  • Sr. Member
  • ****
  • Posts: 344
  • Former Delphi 7 and Delphi 10.2 User
Re: Loading a Listbox
« Reply #1 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.
o Lazarus v2.1.0 r62452, FPC v3.3.1 r42644, macOS 10.14.6 (with sup update), Xcode 10.3
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.0 (Parallels VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

JLWest

  • Hero Member
  • *****
  • Posts: 625
Re: Loading a Listbox
« Reply #2 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;
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 2264
Re: Loading a Listbox
« Reply #3 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!
« Last Edit: January 14, 2020, 02:33:37 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 625
Re: Loading a Listbox(Solved)
« Reply #4 on: January 14, 2020, 07:17:35 pm »
Listbox Sort was set to true.

Thank you
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB