Recent

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

JLWest

  • Hero Member
  • *****
  • Posts: 934
[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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1071
  • Former Delphi 1-7, 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 r63871, FPC v3.3.1 r47164, macOS 10.14.6, Xcode 11.3.1
o Lazarus v2.1.0 r64160, FPC v3.3.1 Nov 27 21:16:31, macOS 11.0.1 (aarch64), Xcode 12.2
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (PD VM)

JLWest

  • Hero Member
  • *****
  • Posts: 934
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: 3236
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/FPC 2.0.8/3.0.4 & 2.0.10/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 934
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

 

TinyPortal © 2005-2018