[SOLVED] „Error: Constant and CASE types do not match‟ with string lazarus / 62-General ---------------------------------------------------------------------- CM630 · 2018-07-09 13:31 Following code works right: 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.Button1Click(Sender: TObject);var  A: string='';  B: string= 'B';  C: string= 'C';begin  A:=B;  case A of    'B': ShowMessage (B);    'C': ShowMessage (C);  end;end; But this code generates „Error: Constant and CASE types do not match‟. 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.Button1Click(Sender: TObject);var  A: string='';  B: string= 'B';  C: string= 'C';begin  A:=B;  case A of    B: ShowMessage (B);  C: ShowMessage (C);  end;end; B and C are strings. I tryed to cast to cast them to strings, anyway, but still I get the same error? Is it me doing sth. wrong? ---------------------------------------------------------------------- RayoGlauco · 2018-07-09 13:49 In the second example, you use variables as selectors, instead of constants (B is a variable; 'B' is a constant). You cannot use variables as selectors. See http://wiki.freepascal.org/Case ---------------------------------------------------------------------- Thaddy · 2018-07-09 13:50 Needs a literal value, indeed. ---------------------------------------------------------------------- Gammatester · 2018-07-09 13:50 You should read the second part of the error message 'Error: String expression expected'. The case labels must be constants (i.e. literals or true constants). Your construct would throw equivalent message even for integer variables. The following code does work: 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 var  A: string='';const  B = 'B';  C = 'C';begin  A:=B;  case A of    B: writeln (B);    C: writeln (C);  end;end; ---------------------------------------------------------------------- CM630 · 2018-07-09 13:57 Ok, thanks, I will rewrite it with QuoteIf... then.