Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-07

Variable visibility problem

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexandre Leclerc

Hi all,

in Controls.pas there is TControl.SetName(). In a form I made a procedure with

TMyForm.MyProcedure;
var
  setName: string;
begin
  //...
end;
The compiler complains about: frmMyForm.pas(467,3) Error: Duplicate
identifier "SetName"

It should do no problems. But If I want to use SetName of TControl then I'll specifically invoke it. Normally the local variable should have priority.

Is it a feature of FPC? :) Or should there be a bug filling on that specific issue?

Best regards.

Alexandre Leclerc
Michael Van Canneyt
to Alexandre Leclerc
Alexandre Leclerc wrote 21 lines
Hi all, in Controls.pas there is TControl.SetName(). In a form I made a procedure with TMyForm.MyProcedure; var setName: string; begin //... end; The compiler complains about: frmMyForm.pas(467,3) Error: Duplicate identifier "SetName" It should do no problems. But If I want to use SetName of TControl then I'll specifically invoke it. Normally the local variable should have priority. Is it a feature of FPC? :) Or should there be a bug filling on that specific issue?

This is not a bug.
Your code will compile in DELPHI mode, but not in FPC mode.

Michael.

Alexandre Leclerc
to Michael Van Canneyt

2006/7/12, Michael Van Canneyt :

This is not a bug. Your code will compile in DELPHI mode, but not in FPC mode.

Ok, I do not want Delphi mode (I try never using this mode: I code in FPC isn't it?). But as a side question, is there a reason we can't do that in FPC? I should restate: What is the design reason for this decision/behaviour? Is it the way 'pascal object' is supposed to behave?

Alexandre Leclerc
Michael Van Canneyt
to Alexandre Leclerc
Alexandre Leclerc wrote 9 lines
2006/7/12, Michael Van Canneyt : > This is not a bug. > Your code will compile in DELPHI mode, but not in FPC mode. Ok, I do not want Delphi mode (I try never using this mode: I code in FPC isn't it?). But as a side question, is there a reason we can't do that in FPC? I should restate: What is the design reason for this decision/behaviour? Is it the way 'pascal object' is supposed to behave?

It's not good practice to have local variables with the same name as a public method/property. How will you tell which one is used ? (obviously you can find out, but at first glance it will not be clear)

Michael.

Alexandre Leclerc
to Michael Van Canneyt

2006/7/12, Michael Van Canneyt :

It's not good practice to have local variables with the same name as a public method/property. How will you tell which one is used ? (obviously you can find out, but at first glance it will not be clear)

Well, I was always doing Self.SetName in these cases... (as an example here). Same thing for functions implemented in different units (was hapening): unit1.ProcedureInUnit and unit2.ProcedureInUnit. So it was obivious for me since local var always have priority.

I was seeing it exactly as the 'with .. do' block.

But this is ok, I'll work the FPC way. I'm not sure this (FPC) will change anyway :)

Thank you.

Alexandre Leclerc