How copy stringlist texts and objects into a listbox?

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?

tiggermarkAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MerijnBConnect With a Mentor Sr. Software EngineerCommented:
if you don't want to loose previous content of the listbox you can use AddStrings
Listbox1.Items.AddStrings(StringList);
0
 
ziolkoCommented:
Listobox1.Items.Assign(stringlist.lines);

ziolko.
0
 
mikelittlewoodConnect With a Mentor Commented:
Dont need the lines

Listobox1.Items.Assign( Stringlist);
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
tiggermarkAuthor Commented:
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
 
MerijnBSr. Software EngineerCommented:
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
 
tiggermarkAuthor Commented:
Upped the points and split them (I hope) between mikelittlewood and MerijnB.

Thanks. Both comments highly useful.

Mark
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.