[lazarus] Possible compiler bug with derived classes?

Chris Storah cstorah at emis-support.demon.co.uk
Thu Nov 4 05:52:30 EST 1999


Just found a piece of code that may or may not clarify things:
(TField sample in the Delphi help)...

Problem is not limited to variables - constructors have the same problem if
the parameters names conflict.

The compiler gets conflicts for FNAME, X anf Y, but not Value - why has
Value got through, as it's name is re-used?

Cheers,
Chris.

{================================}
TField = class
private
  X, Y, Len: Integer;
  FName: String;
public
  constructor Copy(F: TField);
  constructor Create(FX, FY, FLen: Integer; FName: String);
  destructor destroy; override;
  procedure Display; virtual;
  procedure Edit; dynamic;
protected
  function GetStr: String; virtual;
  function PutStr(S: String): Boolean; virtual;
private
  procedure DisplayStr(X, Y: Integer; S: String);
public
  property Name: String read GetStr write Buffer;
end;


  TStrField = class(TField)
  private
    Value: PString;
  public
    constructor Create(FX, FY, FLen: Integer; FName: String);
    destructor Destroy; override;
  protected
    function GetStr: String; override;
    function PutStr(S: String): Boolean; override;
  end;

  TNumField = class(TField)
  private
    Value, Min, Max: Longint;
  public
    constructor Create(FX, FY, FLen: Integer; FName: String;
      FMin, FMax: Longint);
    function GetStr: String; override;

    function PutStr(S: String): Boolean; override;
    function Get: Longint;
    procedure Put(N: Longint);
  end;

{===================================================}


-----Original Message-----
From: Michael Van Canneyt [mailto:michael.vancanneyt at wisa.be]
Sent: 04 November 1999 09:32
To: Lazarus (E-mail)
Subject: Re: [lazarus] Possible compiler bug with derived classes?




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 ?

I agree that for the sake of compatibility, we should accept this, but it is
simply bad programming to do this, so this is not a priority.

Michael.

_________________________________________________________________
     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