Recent

Author Topic: Is it possible to insert into a listbox?  (Read 2880 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Is it possible to insert into a listbox?
« on: December 15, 2018, 05:30:57 pm »
Ive searched the web and the form and can't find anything.

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

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Is it possible to insert into a listbox?
« Reply #1 on: December 15, 2018, 05:43:44 pm »
Yes, two ways. One to the end of the list. The other to a specific location:
Code: Pascal  [Select][+][-]
  1.   ListBox1.Items.Add('To the end');
  2.   ListBox1.Items.Insert(2, 'to the 3rd location');

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Is it possible to insert into a listbox?
« Reply #2 on: December 15, 2018, 07:08:14 pm »
@engkin,
You forgot Append (and maybe addstrings) See the documentation:  https://www.freepascal.org/docs-html/rtl/classes/tstrings.append.html

@JLWest,
It is only proper to examine the documentation first. ListBox.Items inherits from Tstrings, ergo all its methods apply.
« Last Edit: December 15, 2018, 07:10:44 pm by Thaddy »
Specialize a type, not a var.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Is it possible to insert into a listbox?
« Reply #3 on: December 15, 2018, 09:57:45 pm »
@Thaddy

Thank you for the help.

I actually searched   for it and Googled free pascal listbox insert.

The proper search is Free Pascal TStringList Insert.

 
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: 4219
Re: Is it possible to insert into a listbox?
« Reply #4 on: December 15, 2018, 10:17:52 pm »
The proper search is Free Pascal TStringList Insert.

Not really. The proper search is TStrings.Insert; TStringList is just one descendant (granted, the standard descendant) but there are a lot of others ... for example the Items in a TListBox
ETA: TListBox.Items is not a descendant but direclty declared as TStrings.
« Last Edit: December 15, 2018, 10:26:08 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018