[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
GNU Pascal follows the object model of Borland Pascal 7.0. The BP object extensions are almost fully implemented into GPC. This includes inheritance, virtual and non-virtual methods, constructors, destructors, pointer compatibility, extended `New' syntax (with constructor call and/or as a Boolean function), extended `Dispose' syntax (with destructor call).
The Borland object model is different from the ISO draft, but it will not be too difficult now to implement that too (plus the Borland Delphi Object Extensions which are quite similar to the ISO draft).
The syntax for an object type declaration is as follows:
program ObjectDemo; |
Remarks:
var MyFooParent: FooParentPtr; SomeFoo: Foo; [...] SomeFoo.Init (4, 2); MyFooParent := @SomeFoo; MyFooParent^.bar (3.14); { calls `foo.bar' } MyFooParent^.baz ('b', 'a', 'z'); { calls `fooParent.baz' } if SomeFoo.baz then { calls `foo.baz' } WriteLn ('Baz!'); |
procedure Foo.Bar (c: Real); begin z := c; inherited bar (z) { or: FooParent.Bar (z) } end; |
var MyFoo: FooPtr; [...] New (MyFoo, Init (4, 2)); MyFooParent := New (FooPtr, Init (4, 2)) |
Dispose (MyFooParent, Fini) |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |