[fpc-pascal] Extending an enumeration
Ludo Brands
ludo.brands at free.fr
Fri Dec 28 12:59:42 CET 2012
On 28/12/2012 12:48, Mark Morgan Lloyd wrote:
> Ludo Brands wrote:
>> 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;
>
> Thanks, but I was hoping for something the other way round i.e.:
>
> type TCommonServerCapabilitiesBase= (scConnected, scCanIssueGUID);
>
> TLocalServerCapabilitiesBase(TCommonServerCapabilitiesBase) +=
> (lscIsFirebird); // INVALID CODE, EXAMPLE ONLY.
>
> TLocalServerCapabilities= set of TLocalServerCapabilitiesBase;
>
> I'd be fairly happy with any solution that did the necessary
> type/range checking at runtime.
>
Enumerations have an ordinal value that starts with 0 by default.
"Combining" enumerations has to make sure the ordinal values are
different. As a result you can go from bigger to smaller but not the
other way around. In your case with 2 subranges you could do something like:
type
TAllServerCapabilitiesBase=(uscWhatever scConnected,
scCanIssueGUID, lscIsFirebird);
TUpstreamServerCapabilitiesBase= uscWhatever .. uscCanIssueGUID;
TLocalServerCapabilitiesBase= scConnected..lscIsFirebird;
Just make sure you put the common values in the middle.
Ludo
More information about the fpc-pascal
mailing list