Solved

How copy stringlist texts and objects into a listbox?

Posted on 2006-10-19
6
1,855 Views
Last Modified: 2008-02-01
Hi
I'm learning Delphi.
This must be easy.
I have a stringlist filled with rows of text. Each row has an object associated with it.
How do I copy each row's text and object into a listbox?

0
Comment
Question by:tiggermark
6 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17764443
Listobox1.Items.Assign(stringlist.lines);

ziolko.
0
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 50 total points
ID: 17764490
Dont need the lines

Listobox1.Items.Assign( Stringlist);
0
 
LVL 19

Accepted Solution

by:
MerijnB earned 50 total points
ID: 17764503
if you don't want to loose previous content of the listbox you can use AddStrings
Listbox1.Items.AddStrings(StringList);
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:tiggermark
ID: 17765883
Thanks guys, especially mikelittlewood.

Sorry for delay replying. Had to leave the desk and do something else.

For some reason I thought I had to assign each line in a loop using .count and [index].

MerijnB: doesn't AddStrings simply add the strings and not the objects?

Mark
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17766154
nope, from classes.pas:

procedure TStrings.AddStrings(Strings: TStrings);
var
  I: Integer;
begin
  BeginUpdate;
  try
    for I := 0 to Strings.Count - 1 do
      AddObject(Strings[I], Strings.Objects[I]);
  finally
    EndUpdate;
  end;
end;
0
 

Author Comment

by:tiggermark
ID: 17767307
Upped the points and split them (I hope) between mikelittlewood and MerijnB.

Thanks. Both comments highly useful.

Mark
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 119
How to convert memory stream to PDF file 6 128
firemonkey keyboard covers the controls 1 37
migrate this code to wprk on android 1 5
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question