"case style" statements for elements of a set variable? lazarus / 21-General ---------------------------------------------------------------------- 741 · 2025-08-02 10:58 This is what I'm trying to do. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.pbxGridMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin  case Shift of  //Invalid code, but shows what I'd like to achieve     ssLeft: sbrImagZ.Panels[1].Text := 'Left Down';     ssRight: sbrImagZ.Panels[1].Text := 'Right Down';...//etc  end; I can see it is not valid because the set 'Shift' may contain more than one element. Would I have to useCode: [Select]if ssLeft in Shift then //...Maybe theere is a neater way? ---------------------------------------------------------------------- Martin_fr · 2025-08-02 12:11 The short answer is: You can't use case. You have to use the "if" statements. The long answer is, if you want to go on a tricky, slippery path and use some hacked together code .... You can get case do to the job. But as you said "there can be multiple enums set". The "case" will see each combination as a different option. I do _ NOT _ recommend the below. Do not use it. The below is for fun of hacking the code, not for use in any app. It will probably break, if you use any options that change the size of sets. It also depends on the CPU (big endian vs little endian). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Example of really bad codevar  c: TShiftState;begin  c := [ssRight];  // Example of really bad code  case cardinal(c) of    1 << (ord(ssLeft))  : writeln('left');    1 << (ord(ssRight)) : writeln('right');    (1 << (ord(ssLeft))) or    (1 << (ord(ssRight))) : writeln('both');    otherwise      writeln('left/right may still be set, but combined with other enums in the set');  end;end; ---------------------------------------------------------------------- cdbc · 2025-08-02 12:15 Hi There is an old trick, from before one could put strings in a 'case' statement... In unit 'StrUtils' look for this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function AnsiIndexStr(const AText: AnsiString; const AValues: array of AnsiString): Integer;begin  for result:=low(AValues) to High(Avalues) do     if (avalues[result]=AText) Then       exit;                                  // make sure it is the first val.  result:=-1;end; Normally you'd use it like this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...  case AnsiIndexStr('Two',['One','Two','Three','Four']) of    0: showmessage('One');    1: showmessage('Two');    ... etc  end;...MeThinks it would be a small, short task to create a function for TShiftState  Then you could use 'case' for that too  eta: !!! Beware: the above function ONLY returns the first occurrence -- Well in hindsight it's probably a shijty solution, forget 'bout it... Regards Benny ---------------------------------------------------------------------- jamie · 2025-08-02 13:33 To explain it better, TShiftState is a SET with means it represents multiple set values into one. A Case only works with single values like an ENUMERATOR where the object holding the definition holds only one item per case. In this situation, the SET can hold multiple states as indicated.  So using the IN operator is normally the chosen way. Jamie ---------------------------------------------------------------------- jamie · 2025-08-02 13:59 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  Case LongBool(LongInt(Shift) and ((Ord(ssCtrl)+1) Shl Ord(ssCtrl))) Of   true:Caption := DateTimeTostr(Now);   False:Caption := 'Control not down';  End;end;                               To give you a perspective of what it would be like to use a case statement for just one item in the set. Jamie ---------------------------------------------------------------------- jamie · 2025-08-02 14:05 But Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer); Var   I :TShiftStateEnum;   S:String;begin  S:= 'Nothing pressed';  For I in Shift do   Case I of     ssShift :S := 'Shift';   ssAlt   :S := 'Alt Key';     ssCtrl  :S:= 'Control Key';   end;  Caption := S;end;                                         jamie ---------------------------------------------------------------------- d2010 · 2025-08-02 15:24 Quote from: jamie on August 02, 2025, 04:05:14 pmBut Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,end;                                     jamie Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer); Var   I :TShiftStateEnum;   S:String;begin  S:='';  For I in Shift do   Case I of     ssShift :S := s+'Shift+';     ssAlt   :S := s+'Alt Key+';     ssCtrl  :S:= s+'Control Key+';   end;  if length(s)<03 then caption:='Nothing pressed ! Please you try again<