Lazarus
Programming => General => Topic started by: coolmyf 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.
-
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
-
Thanks.
I add {$mode delphi}. It works.
-
I add {$mode delphi}. It works.
It is better to change the name of the parameter, and even put the modifier "const" before it.