[Lazarus] Attn Michael, uses section

Mattias Gaertner nc-gaertnma at netcologne.de
Thu May 18 14:17:54 CEST 2017


On Thu, 18 May 2017 13:46:07 +0200
Joe via Lazarus <lazarus at lists.lazarus-ide.org> wrote:

>[...]
> > Either move the Windows unit in front of the SysUtils unit, or use
> > SysUtils.GetEnvironmentVariable
> 
> Yes, both solutions work; thank you, Martin and Mattias. Are they 
> documented anywhere?

The rule is simple:
If an identifier is searched via the uses section, and it does not
start with a unitname, the interfaces of the units of the uses section
are searched from right to the left.


Michael, where are the uses section resolve rules explained?
I would expect the documentation of the uses section somewhere
here:
https://www.freepascal.org/docs-html/current/ref/refse106.html#x216-23800016.2


Btw, the docs about Dotted units
https://www.freepascal.org/docs-html/current/ref/refse107.html
states:
"When resolving symbols, unit scopes always take precedence over symbols
inside units."

IMO this is misleading. For example:

uses foo;
type
  TMy = class
    foo: TMy;
    procedure DoSome;
  end;
procedure TMy.DoSome;
begin
  foo:=nil; // nearest symbol wins
  foo.foo:=nil; // symbol inside unit wins
end;

The rule is more like this:
If the first symbol of a dotted identifier is an unit in the uses
section, the longest match wins.


Mattias


More information about the Lazarus mailing list