Ludo Brands wrote:
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;
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.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal