[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

9.286 TypeOf

Synopsis

 
function TypeOf (var x): PObjectType;

Description

Returns a pointer to the VMT of an object type or variable. This pointer can be used to identify the type of an object.

`TypeOf' can be applied to expressions of object type and to object type names. In the former case, the actual type of polymorphic objects is returned.

Conforming to

ISO Pascal does not define `TypeOf', Borland Pascal does.

Example

 
program TypeOfDemo;
type
  FooPtr = ^Foo;
  BarPtr = ^Bar;

Foo = object { Has a VMT, though it doesn't } x: Integer; { contain virtual methods. } constructor Init; end;

Bar = object (Foo) y: Integer; end;

constructor Foo.Init; begin end;

var MyFoo: FooPtr;

begin MyFoo := New (BarPtr, Init); if TypeOf (MyFoo^) = TypeOf (Bar) then { True } WriteLn ('OK') end.

See also

section 9.26 BitSizeOf, section 9.5 AlignOf, section 9.195 PObjectType, section 9.247 SetType, section 9.257 SizeOf, section 8.8 Object-Orientated Programming.



This document was generated by Frank Heckenbach on May, 10 2002 using texi2html