[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'Objects' (#rtl)

TCollection.Free

Free item from collection, calling it's destructor.

Declaration

Source position: objects.pp line 415

procedure TCollection.Free(

  Item: Pointer

);

Description

Free Deletes Item from the collection, and calls the destructor Done of the object.

Errors

If the Item is not in the collection, Error will be called with coIndexError.

See also

TCollection.FreeItem

  

Destroy a non-nil item.

Example

Program ex30;

{ Program to demonstrate the TCollection.Free method }

Uses Objects,MyObject; { For TMyObject definition and registration }

Var C : PCollection;
    M : PMyObject;
    I : Longint;

begin
  Randomize;
  C:=New(PCollection,Init(120,10));
  For I:=1 to 100 do
    begin
    M:=New(PMyObject,Init);
    M^.SetField(I-1);
    C^.Insert(M);
    end;
  Writeln ('Added 100 Items.');
  With C^ do
    While Count>0 do Free(At(Count-1));
  Writeln ('Freed all objects.');
  Dispose(C,Done);
end.

Documentation generated on: Mar 17 2017