Sign in Join

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

Mailing lists / fpc-pascal / 2010-05

identifier scope problem

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

leledumbo

consider the following code snippet:
<code>
unit a;

interface
type
  tt = ...
  tcls = class
  procedure method(x,y: tt);
  end;
function equals(x,y: tt): boolean;
implementation
function equals(x,y: tt): boolean;
begin
  ...
end;
procedure tcls.method(x,y: tt);
begin
  if equals(x,y) then
    ...
end;
end.
</code>

In the code above, equals will refer to tobject.equals instead of equals defined in the unit. How can I refer to that one instead?

View this message in context: http://old.nabble.com/identifier-scope-problem-tp28443031p28443031.html Sent from the Free Pascal - General mailing list .
David Emerson
to leledumbo
leledumbo wrote
In the code above, equals will refer to tobject.equals instead of equals defined in the unit. How can I refer to that one instead?

I'm unable to reproduce your error. Real code that I could actually compile and run would make this a lot easier.

That said, have you tried unitname.equals?

Cheers,
David

Thierry Coq
to leledumbo: consider the following code snippet: <code> unit a; interface type tt = ... tcls = class…

try prefixing by the unit name:

procedure tcls.method(x,y: tt);
begin
  if a.equals(x,y) then
    ...
end;

Thierry

leledumbo wrote 34 lines
consider the following code snippet: <code> unit a; interface type tt = ... tcls = class procedure method(x,y: tt); end; function equals(x,y: tt): boolean; implementation function equals(x,y: tt): boolean; begin ... end; procedure tcls.method(x,y: tt); begin if equals(x,y) then ... end; end. </code> In the code above, equals will refer to tobject.equals instead of equals defined in the unit. How can I refer to that one instead?
leledumbo
to Thierry Coq
I'm unable to reproduce your error. Real code that I could actually compile

and

run would make this a lot easier.

Perhaps you're using an old version of the compiler where TObject doesn't have Equals method (added for Delphi compatibility along with UnitName and ToString)

prefixing by the unit name

Oops! That works, thanks. I thought only units listed in the uses list can be accessed through that syntax.

View this message in context: http://old.nabble.com/identifier-scope-problem-tp28443031p28469702.html Sent from the Free Pascal - General mailing list .