-1

Ex:

var
 Msg: Cardinal;
case Msg of
      WM_CHAR:
      WM_KEYDOWN:
      WM_KEYUP:
        begin
         // Do something
        end;

    end;
Kromster
  • 7,181
  • 7
  • 63
  • 111
FLASHCODER
  • 1
  • 7
  • 24
  • 1
    What have you tried? What error / behavior does it exhibit? What are you trying to accomplish? – mirtheil Apr 16 '19 at 17:46
  • @mirtheil, the error was on **:** of `WM_KEYDOWN` that said: "Expected *END* but received **:**". – FLASHCODER Apr 16 '19 at 18:02
  • 3
    I just want to say, if you read the documentation, non of your previous question including this would have found a place here, just read the documentation and all will be answered mostly, And when you reach that level then come ask here. – Nasreddine Galfout Apr 16 '19 at 18:12
  • For your convenience, here it is http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Declarations_and_Statements_(Delphi)#Case_Statements . – Sertac Akyuz Apr 16 '19 at 18:13

2 Answers2

7

Use commas to separate the labels:

var
  Msg: Cardinal;
... 
case Msg of
  WM_CHAR,
  WM_KEYDOWN,
  WM_KEYUP:
    begin
      // Do something
    end;
end;

As @SertacAkyuz mentioned, if the values are consecutive, you can do something like:

case Msg of
  WM_KEYDOWN .. WM_CHAR: // range 
    begin
      // Do something
    end;
end;
Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • Sertac: yes, indeed, although I would probably not use it for such message constants. It can work if you know the exact order, but I don't (and don't want to memorize them either). – Rudy Velthuis Apr 16 '19 at 18:06
  • 2
    Yes, for this case it just makes the constants obscure. But good to know for when it makes sense, like: wm_keyfirst .. wm_keylast. – Sertac Akyuz Apr 16 '19 at 18:10
1

Assuming you want "Do Something" to be executed in all three cases you have to separate the case labels with comma:

var
  Msg: Cardinal;

case Msg of
  WM_CHAR,
  WM_KEYDOWN,
  WM_KEYUP:
        begin
         // Do something
        end;
end;
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130