Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy the value of one pointer to another???? 2

Status
Not open for further replies.

ivoestg

Programmer
Mar 21, 2001
77
PT
how can i copy the value of a tlist to other tlist,then destroy the first tlist and keep the values in the second tlist...can you dend me the code to do that? thanks...
 
I'm not sure if this is what you're looking for...


procedure CopyList(fromList,toList: TList);
var x: longint;
begin
for x := 0 to fromList.count-1 do
begin
toList.Add(fromList[x]);
end;
end;


That procedure will put all of the items in the first list into the second list. Then you can safely free the first list. Freeing a list does not free the objects in the list so the second list will have the same data that the first had, if that makes sense. :)

Good luck!
TealWren
 
Hi Ivoestg

It is possible to copy the whole list lista := listb , but tealwrens solution is safer. and more likly to work.

You need to clear the data out of list objects before freeing them as suggested.

e.g.
fromlist.clear;
fromlist.free;

Steve



 
Actually, a Clear won't free the data objects either. You have to loop through the list and free them yourself. Clear just clears the pointers out of the list. TealWren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top