Recent

Author Topic: case and utf8  (Read 2467 times)

BobS

  • Full Member
  • ***
  • Posts: 153
case and utf8
« on: October 24, 2015, 09:13:56 am »
The following code fragment will cause a "constant and case type do not match" error as indicated (it's been extracted from a utf8keypress event):

Code: Pascal  [Select][+][-]
  1.    var UTF8Key: TUTF8Char;
  2.  begin
  3.    case UTF8Key of
  4.          '1': (*do something*);
  5.          '2': (*do something else*);
  6.         (*and so on until the next line*)
  7.          DefaultFormatSettings.DecimalSeparator: (*do something crazy*); //ERROR
  8.      end;  
I've tried type casting as both TUTF8Char and string but it still cause problems.

The only option I've found is to add an else clause to handle the DecimalSeparator in a comparison:
Code: Pascal  [Select][+][-]
  1.  if UTF8Key = DefaultFormatSettings.DecimalSeparator
  2.            then  (*do something crazy*)
which works fine.   I'm really just trying to make my program a bit more versatile without having to go into learning all the details of codepages etc (for now).  I'd like to use ThousandSeparator too and maybe others so really would like to just use the case statement without extra conditionals for this (especially in something called every key press).

christian1987

  • New Member
  • *
  • Posts: 30
Re: case and utf8
« Reply #1 on: October 24, 2015, 09:58:18 am »
Show more code.

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: case and utf8
« Reply #2 on: October 24, 2015, 11:49:04 am »
case labels have to be constant expressions (known value at compile time). That is the same for strings and any other type that can be used with "case".

BobS

  • Full Member
  • ***
  • Posts: 153
Re: case and utf8
« Reply #3 on: October 25, 2015, 01:17:14 am »
Yep, totally forgotten that...back to Pascal 101 ;).  Thanks.
« Last Edit: October 25, 2015, 01:28:56 am by BobS »

 

TinyPortal © 2005-2018