[lazarus] Possible compiler bug with derived classes?
Marc Weustink
Marc.Weustink at cuperus.nl
Thu Nov 4 06:18:18 EST 1999
+ 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
More information about the Lazarus
mailing list