Recent

Author Topic: Duplicate Identifier  (Read 1239 times)

coolmyf

  • Newbie
  • Posts: 3
Duplicate Identifier
« on: May 29, 2019, 05:23:53 am »
I wrote a simple program as below. When I compile it, the Lazarus compiler gives "Duplicate Identifier 'Name' Error".But the same code can be compiled smoothly in Delphi XE10. Could anyone tell me why?Thanks.

program Project1;

type

  { TMyobj }

  TMyobj=class
    public
      Name:string;
      constructor Create(Name:string);
      procedure writename;
  end;

{ TMyobj }

constructor TMyobj.Create(Name: string);
begin
  self.Name:=Name;
end;

procedure TMyobj.writename;
begin
   writeln(name);
end;

var MyObj:TMyobj;
begin
  MyObj:=TMyObj.Create('Mark');
  MyObj.writename;
  MyObj.Free;
  readln;
end.

Awkward

  • Full Member
  • ***
  • Posts: 135
Re: Duplicate Identifier
« Reply #1 on: May 29, 2019, 06:10:48 am »
try to use {$MODE DELPHI}
or check {$MODESWITCH DUPLICATELOCALS-} macro
but i prefer to use method headers like this:
constructor TMyobj.Create(aName: string);
i.e. not to use arguments and locals like class fields

coolmyf

  • Newbie
  • Posts: 3
Re: Duplicate Identifier
« Reply #2 on: May 29, 2019, 06:35:52 am »
Thanks.
I add {$mode delphi}. It works.

ASerge

  • Hero Member
  • *****
  • Posts: 2242
Re: Duplicate Identifier
« Reply #3 on: May 29, 2019, 02:39:04 pm »
I add {$mode delphi}. It works.
It is better to change the name of the parameter, and even put the modifier "const" before it.

 

TinyPortal © 2005-2018