Solved

How copy stringlist texts and objects into a listbox?

Posted on 2006-10-19
6
1,739 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
Comment Utility
Listobox1.Items.Assign(stringlist.lines);

ziolko.
0
 
LVL 15

Assisted Solution

by:mikelittlewood
mikelittlewood earned 50 total points
Comment Utility
Dont need the lines

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

Accepted Solution

by:
MerijnB earned 50 total points
Comment Utility
if you don't want to loose previous content of the listbox you can use AddStrings
Listbox1.Items.AddStrings(StringList);
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:tiggermark
Comment Utility
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
Comment Utility
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
Comment Utility
Upped the points and split them (I hope) between mikelittlewood and MerijnB.

Thanks. Both comments highly useful.

Mark
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now