17.5 TObject

The full declaration of the TObject type is:

 TYPE
    TObject = OBJECT
       CONSTRUCTOR Init;
       PROCEDURE Free;
       DESTRUCTOR Done;Virtual;
    END;
    PObject = ^TObject;

TObject.Init

Declaration:
Constructor TObject.Init;
Description:
Instantiates a new object of type TObject. It fills the instance up with Zero bytes.
Errors:
None.
See also:
Free (563), Done (564)

For an example, see Free (563)

TObject.Free

Declaration:
Procedure TObject.Free;
Description:
Free calls the destructor of the object, and releases the memory occupied by the instance of the object.
Errors:
No checking is performed to see whether self is nil and whether the object is indeed allocated on the heap.
See also:
Init (563), Done (564)

Listing: objectex/ex7.pp


program ex7;

{ Program to demonstrate the TObject.Free call }

Uses Objects;

Var O : PObject;

begin
  Writeln ('Memavail : ',Memavail);
  // Allocate memory for object.
  O:=New(PObject,Init);
  Writeln ('Memavail : ',Memavail);
  // Free memory of object.
  O^.free;
  Writeln ('Memavail : ',Memavail);
end.

TObject.Done

Declaration:
Destructor TObject.Done;Virtual;
Description:
Done, the destructor of TObject does nothing. It is mainly intended to be used in the TObject.Free (563) method.

The destructore Done does not free the memory occupied by the object.

Errors:
None.
See also:
Free (563), Init (563)

Listing: objectex/ex8.pp


program ex8;

{ Program to demonstrate the TObject.Done call }

Uses Objects;

Var O : PObject;

begin
  Writeln ('Memavail : ',Memavail);
  // Allocate memory for object.
  O:=New(PObject,Init);
  Writeln ('Memavail : ',Memavail);
  O^.Done;
  Writeln ('Memavail : ',Memavail);
end.