Objects and GPC

Fri, 4 Apr 1997 14:20:56 +0000 (GMT)


Hiya!

Using the latest GPC alpha (9704), I find that I cannot
import objects from a unit. I originally had the source 
for TObject (below) in a unit, and used the unit in
this program (test.pas). I had compile errors all
the time. Then, I put the object's source into test.pas
itself, and it compiled. But when I tried to create
a descendant object (NewObj), as seen in the
source below, again, I had compile errors - 
complaining about the "initializer element" for
some of the methods not being "constant".

Can anyone tell why this source does not compile,
even with the -borland-pascal flag? It compiles and
runs okay with BP7 and BPW. Thanks!

{ ---- cut -----}
Program Test;

{$define debug}

Type
pObject  = ^TObject;
ChildPtr = pObject;

TObject  = Object
   Parent      : pObject;
   Child       : ChildPtr;
   Name        : String[255];
   Handle      : integer;

   { BP }
   Constructor Init;
   Destructor  Done;virtual;

   { Delphi }
   Procedure   Free;virtual;  {calls Destroy}
   Destructor  Destroy;virtual;
   Constructor Create (aOwner : pObject);
End; { TObject }

Constructor TObject.Init;
Begin
   Parent := Nil;
End; { TObject.Init }
{////////////}
Constructor TObject.Create;
Begin
   Parent := aOwner;
End; { TObject.Create }
{////////////}
Destructor TObject.Done;
Begin
   Handle := 0;
   Name   := '';
   Parent := Nil;
End; { TObject.Done }
{////////////}
Destructor TObject.Destroy;
Begin
   Handle := 0;
   Name   := '';
   Parent := Nil;
End; { TObject.Destroy }
{////////////}
Procedure TObject.Free;
Begin
   {$ifdef debug}Writeln ('Free!');{$endif debug}
   Dispose (pObject (@Self), Destroy);
End; { TObject.Free }
{////////////}

Type
PNewObj = ^NewObj;
NewObj  = Object (TObject)
   Constructor Create (aOwner:PObject);
End; { NewObj }

Constructor NewObj.Create;
Begin
   Inherited Create (aOwner);
   Name := 'Object Number 2 is a Child!';
   Handle := -40;
End; { NewObj.Create }

{ Program() }
Var
ThisObj : TObject;
Begin
  Writeln ('Hello World!');
  ThisObj.Init;
  With ThisObj do begin
     Handle := -1;
     Name   := 'Object Number 1';
     Child  := New (PNewObj, Create (@ThisObj) );
     Writeln ('My handle    = ', Handle);
     Writeln ('My name      = ', Name);
     Writeln ('Child handle = ', Child^.Handle);
     Writeln ('Child name   = ', Child^.Name);
     Writeln ('Child PARENT handle = ', Child^.Parent^.Handle);
     Child^.Free;
     Done;
  end; { With Ob^ }
  Writeln ('Hello World Number 2 !!');
End { Program() }.

{ --- end cut ---}

Best regards, The Chief 
Dr Abimbola A. Olowofoyeku (The African Chief, and the Great Elephant)
Author of:  Chief's Installer Pro v3.12 for Win16 and Win32.
Homepage:  http://ourworld.compuserve.com/homepages/African_Chief/
E-mail: laa12@cc.keele.ac.uk



The African Chief (laa12@cc.keele.ac.uk)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es