CASE from a control's Text property lazarus / 31-LCL ---------------------------------------------------------------------- MarkMLl · 2020-05-19 15:41 I have some definitions like this, followed by a CASE statement as shown: Code: [Select]const   a0= #$2191;                           (* ↑                                  *)   a1= #$2197;                           (* ↗                                  *)   a2= #$2192;                           (* →                                  *) ...       case DebugForm.StatusBar1.Panels[0].Text of         a0: DebugForm.StatusBar1.Panels[0].Text := a1;         a4: DebugForm.StatusBar1.Panels[0].Text := a5; // Line 812, char 59 is end of line ... If I have those arrow characters inline as quoted literals it works fine, but as shown I get watchp0xcode.pas(812,11) Error: duplicate case label watchp0xcode.pas(812,59) Warning: Unicode constant cast with potential data loss In practice I need to use constants since I find I've got different systems with slightly different gamuts of Unicode character set available. What is the correct syntax to use here? The area of application is a single-character "twiddler" so that I can keep track of two interlocked counter which aren't behaving quite as expected. Lazarus trunk/2.1.0 with FPC 3.0.4. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-19 17:17 Hi! The char confusion continues ..... The syntax is here: 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 Const a0 : widechar = #$2191;.... For what the hell do you need the gamut of UTF8 symbols? Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-19 17:35 With Code: [Select]const   a0: widechar= #$2191;                 (* ↑                                  *)   a1: widechar= #$2197;                 (* ↗                                  *) ...       case Udp79DebugForm.StatusBar1.Panels[0].Text of         a0: Udp79DebugForm.StatusBar1.Panels[0].Text := a1; // Line 811 I still get watchp0xcode.pas(811,11) Error: Constant and CASE types do not match watchp0xcode.pas(811,11) Error: String expression expected watchp0xcode.pas(811,59) Warning: Implicit string type conversion with potential data loss from "WideChar" to "TTranslateString" I didn't say that I needed the whole Unicode gamut, I said that different systems had slightly different gamuts depending on distro age. Needless to say that included some of the initial arrow etc. shapes I tried, I'm trying to track down a problem with some timers that worked properly with Delphi on Windows but is going reentrant with Lazarus on Linux. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-19 17:52 Hi! Change it into 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 Udp79DebugForm.StatusBar1.Panels[0].Text of        a0: Udp79DebugForm.StatusBar1.Panels[0].Text := WidecharToString(a1); But as this is only unnecessary work, I would recommend the simple solution mentioned by yourself: 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 const a0 = '↑';a1 = '↗';.... Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-19 18:23 Quote from: winni on May 19, 2020, 07:52:24 pmChange it into 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 Udp79DebugForm.StatusBar1.Panels[0].Text of        a0: Udp79DebugForm.StatusBar1.Panels[0].Text := WidecharToString(a1); I'm afraid that doesn't help, since it's the case selector that's still broken rather than the assignment. QuoteBut as this is only unnecessary work, I would recommend the simple solution mentioned by yourself: 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 const a0 = '↑';a1 = '↗';.... Ouch :-( Well it works and I suppose that I can put the numeric codepoint in as a comment, but is that really the only way to do it? Still, it's demonstrating that the interlocked increment/decrement I've got on this timer handler isn't effective for some reason, so under the circumstances... MarkMLl ---------------------------------------------------------------------- winni · 2020-05-19 18:35 Hi! I fooled around with a lot of const types for UTF8 chars and you can go realy complicated ways. So for me it is the easiest way to put them as literals in the code. And nobody forces you to call the const A0, A1 .... 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     const  ArrowNorth        = '↑';    ArrowNorthEast = '↗';    .... To put the UTF8 chars in strings is robust. And even this is ok: 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 consthotlist ='☮±÷℃ ∫≦≧∞⨀⨌  ⟁ ⧉ ⇶⬣ ⬳ ◆☎☭☯♆♬⚓ ❎ 🚦😈 🤖 🧲 ⚽ 🌍 🍀 👀  🕘';  Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-19 19:45 Quote from: winni on May 19, 2020, 08:35:55 pmI fooled around with a lot of const types for UTF8 chars and you can go realy complicated ways. So for me it is the easiest way to put them as literals in the code. OK OK, I believe you :-) QuoteAnd nobody forces you to call the const A0, A1 .... I normally avoid excessively-concise names, but there's a good reason in this case. a0..a7 are eight states for a rotating arrow used as a "twiddler" (four states per second), but the codepoints might be in an odd order (depending on which eight arrows I choose) and I don't want to clash with "official" Unicode names. There's also b0 through b7, which are blocks into which an arrow changes if the state transition sequence is wrong- reentry etc. Once the twiddler has changed into a block it stays there, even if the program /appears/ to be working properly. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-19 20:55 Hi To make twiddling easier: 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 const A : array[0..7] of string[4] = (                   '↑','↗','→','↘','↓','↙','←','↖');   [/size] Winni ---------------------------------------------------------------------- MarkMLl · 2020-05-23 20:30 Quote from: winni on May 19, 2020, 10:55:02 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const A : array[0..7] of string[4] = (                   '↑','↗','→','↘','↓','↙','←','↖');   [/size] Rather belatedly, can I please register how distasteful I find this since the  string[4]  is "magic" required by the character set encoding which should be invisible to the programmer. MarkMLl ---------------------------------------------------------------------- winni · 2020-05-23 22:19 Hi! Okay - if you want to waste bytes then use instead of string[4] TUTF8Char - that is string[7]. Winni