Главная страница | назад





Article #17811: Freeing an object stored in a list.

 Question and Answer Database
FAQ2811D.txt Freeing an object stored in a list.
Category :VCL
Platform :All
Product :All 32 bit
Question:
When I add an object to a TStrings component, how should I free the
object?
Answer:
Simply call the objects free method. The following example attaches
a icon object to the strings property of a listbox during the forms
creation, and frees the icon when the form is destroyed.
Example:
procedure TForm1.FormCreate(Sender: TObject);
var
Icon: TIcon;
begin
Icon := TIcon.Create;
Icon.LoadFromFile('C:\Program Files\BorlandImages\CONSTRUC.ICO');
ListBox1.Items.AddObject('Item 0', Icon);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ListBox1.Items.Objects[0].Free;
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99