Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Liberar objetos que se han añadido a un TList (https://www.clubdelphi.com/foros/showthread.php?t=14974)

neon 06-10-2004 14:24:52

Liberar objetos que se han añadido a un TList
 
Para liberar objetos que se han añadido a un TList, ¿si eliminamos el tlist? tambien se liberan los objetos creados. O por lo contrario tenemos que recorrer el TList y liberarlos uno a uno

roman 06-10-2004 15:21:14

Cita:

Empezado por neon
Para liberar objetos que se han añadido a un TList, ¿si eliminamos el tlist? tambien se liberan los objetos creados.

No


Cita:

Empezado por neon
O por lo contrario tenemos que recorrer el TList y liberarlos uno a uno

Sí. O bien usar un TObjectList de la unidad Contnrs que es similar al TList pero con la opción de sí liberar los objetos.

// Saludos

jplj 07-10-2004 08:53:05

¿ Roman, la forma correcta de hacerlo seria esta ?

Código Delphi [-]

  Lista: TList;


var
   Obj: TClaseObjetosDeLaLista;

begin
   
   Obj:= Lista.Items[i];
   Obj.Free;
   Lista.Delete(i);
   Lista.Capacity := Lista.Count - 1;

walrus 07-10-2004 18:47:54

Yo lo haría así:

Código Delphi [-]
 
for i:= Pred( Lista.Count ) downto 0 do TObject( Lista[i] ).Free;
Lista.Clear;
Lista.Capacity := 0;

Saludos.


La franja horaria es GMT +2. Ahora son las 11:16:00.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi