[fpc-pascal] Extending an enumeration

Ludo Brands ludo.brands at free.fr
Fri Dec 28 12:26:09 CET 2012


On 28/12/2012 11:42, Mark Morgan Lloyd wrote:
> Is it possible to extend an enumeration, while preserving strong type 
> checking? In other words, given existing code like
>
> type    TUpstreamServerCapabilitiesBase= (uscConnected, uscCanIssueGUID);
>         TLocalServerCapabilitiesBase= (lscConnected, lscCanIssueGUID, 
> lscIsFirebird);
>
>         TUpstreamServerCapabilities= set of 
> TUpstreamServerCapabilitiesBase;
>         TLocalServerCapabilities= set of TLocalServerCapabilitiesBase;
>
> can the common parts of those enumerations- whether a connection was 
> initially established and so on- be moved into a common declaration, 
> preferably using "classical" Pascal so that I can store capabilities 
> as a set?
>
Not sure I understand what you are trying to do but perhaps you are 
looking for subrange types:

type
    TAllServerCapabilitiesBase=(uscConnected, 
uscCanIssueGUID,lscConnected, lscCanIssueGUID, lscIsFirebird);
    TUpstreamServerCapabilitiesBase= uscConnected .. uscCanIssueGUID;
    TLocalServerCapabilitiesBase= lscConnected..lscIsFirebird;

    TAllServerCapabiliets=set of TAllServerCapabilitiesBase;
    TUpstreamServerCapabilities= set of TUpstreamServerCapabilitiesBase;
    TLocalServerCapabilities= set of TLocalServerCapabilitiesBase;

Ludo



More information about the fpc-pascal mailing list