Case of statement

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


Your Ad Here

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 untyped 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

Delphi Script statements

If Then statement

With statement

For To Do loop

Repeat Until loop

Continue statement

Exit statement

Break Statement

Your Ad Here