Forum > General

case and utf8

(1/1)

BobS:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---   var UTF8Key: TUTF8Char; begin    case UTF8Key of         '1': (*do something*);         '2': (*do something else*);        (*and so on until the next line*)         DefaultFormatSettings.DecimalSeparator: (*do something crazy*); //ERROR     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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if UTF8Key = DefaultFormatSettings.DecimalSeparator           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:
Show more code.

Jonas Maebe:
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:
Yep, totally forgotten that...back to Pascal 101 ;).  Thanks.

Navigation

[0] Message Index

Go to full version