Case

www.kxcad.net Home > Electronic Index > Altium(Protel) Index


Your Ad Here

Declaration

Case expression Of

    Value range : Expression;

    Else Expression;

End;

Description

The case statements select one branch out of many possible branches depending on the value of the expression.

If you have very complex if statements, at times you can replace them with case statements. A case statement in an expression is used to select a value, a list of possible values, or a range of values. Any types can be used in a Case statement because DelphiScript is an un-typed language.  Case statements can have an else statement that is executed if none of the labels correspond to the value of the selector (within the Case Of condition).

Example 1

Case Char Of

    '+'     : Text := 'Plus sign';

    '-'     : Text := 'Minus sign';

    '*', '/': Text := 'Multiplication or division';

    '0'..'9': Text := 'Number';

    'a'..'z': Text := 'Lowercase character';

    'A'..'Z': Text := 'Uppercase character';

    Else

        Text := 'Unknown character';

End;

Example 2

Case UserName of

    Jack', 'Joe' : IsAdministrator := true;

    ‘Fred' : IsAdministrator := false;

    else

    raise('Unknown User');

End;

See also

Of keyword.

Your Ad Here