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

TCollection.Delete

Delete an item from the collection, but does not destroy it.

Declaration

Source position: objects.pp line 414

procedure TCollection.Delete(

  Item: Pointer

);

Description

Deletedeletes Itemfrom the collection. It doesn't call the item's destructor, though. For this the Freecall is provided.

Errors

If the Itemis not in the collection, Errorwill be called with coIndexError.

See also

TCollection.AtDelete

  

Delete item at certain position.

TCollection.Free

  

Free item from collection, calling it's destructor.

Example

Program ex31;

{ Program to demonstrate the TCollection.Delete 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 Delete(At(Count-1));
  Writeln ('Freed all objects');
  Dispose(C,Done);
end.