Variable visibility problem

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Variable visibility problem

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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Variable visibility problem

Michael Van Canneyt


On Wed, 12 Jul 2006, Alexandre Leclerc wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Variable visibility problem

Alexandre Leclerc
2006/7/12, Michael Van Canneyt <[hidden email]>:
> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Variable visibility problem

Michael Van Canneyt


On Wed, 12 Jul 2006, Alexandre Leclerc wrote:

> 2006/7/12, Michael Van Canneyt <[hidden email]>:
>> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Variable visibility problem

Alexandre Leclerc
2006/7/12, Michael Van Canneyt <[hidden email]>:
> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal