Board index » delphi » Quick Question re: TStringList

Quick Question re: TStringList

Does anyone know off the top of their heads if assigning
a TStrings object also carries along the objects in the
Objects property? In other words:

ACheckListBox : TCheckListBox;
AStringList   : TStringList;

Items and objects have been assigned to ACheckListBox,
for example ACheckListBox.Items.AddObject(AString, TObject(AnObject));

then:

AStringList := TStringList.Create;
AStringList.Assign(ACheckListBox.Items);

I just want to make sure this is going to work as
expected before I code it up -- I hate surprises!

Thanks ahead of time...
Chris W.

 

Re:Quick Question re: TStringList


Chris -

They do, but they do not get replicated. So don't destroy any of the
original objects that got assigned to your TStringList.

Good luck.

Kurt

Re:Quick Question re: TStringList


Chris:

Yes it does. You can easily test this yourself with code similar to the
following:

var
  i:     integer;
  list1: TStringList;
  list2: TStringList;
begin
  list1 := TStringList.Create;
  try
    list2 := TStringList.Create;;
    try
      for i := 1 to 10 do
        list1.AddObject('item ' + IntToStr(i), Pointer(i));

      list2.Assign(list1);

      for i := 0 to list1.Count - 1 do
      begin
        ListBox1.Items.Add(IntToStr(integer(list1.Objects[i])));
        ListBox2.Items.Add(IntToStr(integer(list2.Objects[i])));
      end;
    finally
      list2.Free;
    end;
  finally
    list1.Free;
  end;
end;
--
Regards
Ralph (TeamB)
(No private e-mail replies, please, unless explicitly requested).
--

Quote
Chris Wallace wrote in message <72ct4i$8s...@forums.borland.com>...

|Does anyone know off the top of their heads if assigning
|a TStrings object also carries along the objects in the
|Objects property? In other words:

Other Threads