[fpc-pascal] Boolean case statement

Vincent Snijders vsnijders at quicknet.nl
Tue Dec 5 22:44:12 CET 2006

Terry Kemp schreef:
> Hi All
> how do you do a case statement on a record of booleans e.g...
> Type
>  EngModeRec = Record
>   ManualOp: Boolean;
>   LeakTest: Boolean;
>   DrainFlush: Boolean;
>  end;
> var
>  EngMode: EngModeRec;
> I want to have...
>  Case True of 
>   EngMode.ManualOp: ManualOpRun;
>   EngMode.LeakTest: LeakTestRun;
>   EngMode.DrainFlush: DrainFlushRun;
>  end; 
> but of course this wont work :(

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:

   TEngMode = (emManualOp, emLeakTest, emDrainFlush);

   EngMode : TEngMode;

case EngMode of
   emManualOp: ManualRun;
   emLeakTest: LeakTestRun;
   emDrainFlush: DrainFlushTest;

if several EngMode can occur at the same time (like can happen with 
EngModeRec) you can use

   TEngModeSet = set of TEngMode;

But then you cannot use case anymore to do the tests.


More information about the fpc-pascal mailing list