[fpc-pascal] Enum scope

Sven Barth pascaldragon at googlemail.com
Fri Feb 28 20:22:56 CET 2014


On 28.02.2014 19:59, Marcos Douglas wrote:
> On Fri, Feb 28, 2014 at 3:47 PM, Mattias Gaertner
> <nc-gaertnma at netcologne.de> wrote:
>>
>> On Fri, 28 Feb 2014 15:29:03 -0300
>> Marcos Douglas <md at delfire.net> wrote:
>>
>>> [...]
>>> These properties are defined in Process unit. My class is in myprocess unit
>>> (or something like that).
>>> The problem is: I can not use the enums values because they don't exists in
>>> my unit (myprocess) but if these enums were defined inside TProcess class
>>> (public type), I can use them without problem.
>>>
>>> So, what do you think about it?
>>
>> Enums are always public and global.
>> For example:
>>
>>    TMyClass = class
>>    private
>>      type
>>        MyEnums = (enum1, enum2);
>>    public
>>      e: MyEnums;
>>    end;
>>
>> enum1 can be used in other units.
>
> But that's what I'm talking about!  :)
>
> So if the  TProcessOptions, TProcessPriority and TStartupOptions was
> declared as a type inside TProcess I do not needed to import (uses)
> two units (follow the example: process and myprocess) in a third unit.
>
> I propose "migrate" these enums from units to be member of classes.

Sidenote: What you propose would work only if {$scopedenums on} is used 
in the unit which defines the enums and in that case you'd have the 
problem with backwards compatibility.

Regards,
Sven



More information about the fpc-pascal mailing list