[Lazarus] Attn Michael, uses section

Michael Van Canneyt michael at freepascal.org
Thu May 18 14:29:38 CEST 2017



On Thu, 18 May 2017, Mattias Gaertner via Lazarus wrote:

> 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

Close,
https://www.freepascal.org/docs-html/current/ref/refse105.html#x215-23700016.1

>
>
> 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.

Yes, it is somewhat like black magic :)

I will adapt it.

Michael.


More information about the Lazarus mailing list