[lazarus] Possible compiler bug with derived classes?

Chris Storah cstorah at emis-support.demon.co.uk
Thu Nov 4 07:11:58 EST 1999


That makes sense...maybe Delphi is being clever and automatically adding in
the type-casting '(TVer2)rec' for derived classes? That's good for my code,
but I can see it wouldn't follow standards...

Chris

-----Original Message-----
From: Marc Weustink [mailto:Marc.Weustink at cuperus.nl]
Sent: 04 November 1999 11:18
To: lazarus at miraclec.com
Subject: RE: [lazarus] Possible compiler bug with derived classes?


+ From: michael@[195.207.84.152] [mailto:michael@[195.207.84.152]]On Behalf
Of Michael Van Canneyt

+ On Thu, 4 Nov 1999, Chris Storah wrote:
+
+ > I am having problems when compiling a derived class (WinNT version).
+ > This is the code:
+ >
+ >   TVer1 = class(TObject)
+ >       protected
+ >          rec: TObject;
+ >    end;
+ >
+ >   TVer2 = class(TVer1)
+ >       protected
+ >          rec: TObject;	<=== duplicate identifier
+ >       end;
+ >
+ >
+ > The error using ppc386 is 'Error: Duplicate identifier REC'.
+
+ This IS an error; if you declare such a thing in the protected
+ part, you should rename it. How is the compiler supposed to
+ know in a descendent class which one to take ? Any decision will
+ be necessarily an arbitrary one.
+
+ > Is this a known bug?
+ > If so, anyone know how to fix it without changing the identifier names
+ > (Delphi works with the above code).
+
+ Delphi has other strange quircks; Can you tell me WHICH rec it takes
+ when you refer to it ?

Yes. Its the same as with non virtual methods with the same name.

Example:

var
  v1: TVar1;
  v2: TVar2;
begin
  v1 := TVer1.Create;
  {v1.rec refers to TVer1.rec}

  v2 := TVer2.Create;
  {v2.rec refers to TVer2.rec}

  v1 := TVer2.Create;
  {v1.rec refers to TVer1.rec, since rec is not virtual (mostly for vars
;-)}
  {this same rule applies if rec was a method }

  v2 := TVer2.Create;
  {TVer1(v2).rec refers to TVer1.rec, same rule as above}

  v1 := TVer2.Create;
  {TVer2(v1).rec refers to TVer2.rec}
end;

This is/was somewhere documented, don't know where

Marc

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
    archives at http://www.miraclec.com/list_archives/lazarus






More information about the Lazarus mailing list