[fpc-pascal] Boolean case statement
Terry Kemp
tkemp at klc.net.nz
Tue Dec 5 23:10:36 CET 2006
On Tue, 2006-12-05 at 22:44 +0100, Vincent Snijders wrote:
> Terry Kemp schreef:
> > Hi All
> >
> > how do you do a case statement on a record of booleans e.g...
> >
> You cannot use it like that. You would have to use an nested if then
> statement like:
>
> if EngMode.ManualOp then ManualRun
> else if EngMode.ManualOp then LeakTest
> else etc.
>
>
> I would use an enum:
>
> type
> TEngMode = (emManualOp, emLeakTest, emDrainFlush);
>
> var
> EngMode : TEngMode;
>
> case EngMode of
> emManualOp: ManualRun;
> emLeakTest: LeakTestRun;
> emDrainFlush: DrainFlushTest;
> end;
>
> if several EngMode can occur at the same time (like can happen with
> EngModeRec) you can use
>
> type
> TEngModeSet = set of TEngMode;
>
> But then you cannot use case anymore to do the tests.
>
> HTH,
> Vincent
Hey! I like this enum method - the 'states' are to be mutually exclusive
so this works great.
thanks alot
More information about the fpc-pascal
mailing list