Recent

Author Topic: CASE from a control's Text property  (Read 1507 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
CASE from a control's Text property
« on: May 19, 2020, 05:41:11 pm »
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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2357
Re: CASE from a control's Text property
« Reply #1 on: May 19, 2020, 07:17:17 pm »
Hi!

The char confusion continues .....

The syntax is here:

Code: Pascal  [Select][+][-]
  1. Const
  2. a0 : widechar = #$2191;
  3. ....


For what the hell do you need the gamut of UTF8 symbols?

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
Re: CASE from a control's Text property
« Reply #2 on: May 19, 2020, 07:35:14 pm »
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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2357
Re: CASE from a control's Text property
« Reply #3 on: May 19, 2020, 07:52:24 pm »
Hi!

Change it into
Code: Pascal  [Select][+][-]
  1.  case Udp79DebugForm.StatusBar1.Panels[0].Text of
  2.         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][+][-]
  1. const
  2. a0 = '↑';
  3. a1 = '↗';
  4. ....

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
Re: CASE from a control's Text property
« Reply #4 on: May 19, 2020, 08:23:09 pm »
Change it into
Code: Pascal  [Select][+][-]
  1.  case Udp79DebugForm.StatusBar1.Panels[0].Text of
  2.         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.

Quote
But as this is only unnecessary work, I would recommend the simple solution mentioned by yourself:

Code: Pascal  [Select][+][-]
  1. const
  2. a0 = '↑';
  3. a1 = '↗';
  4. ....

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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2357
Re: CASE from a control's Text property
« Reply #5 on: May 19, 2020, 08:35:55 pm »
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][+][-]
  1.     const
  2.     ArrowNorth        = '↑';
  3.     ArrowNorthEast = '↗';
  4.     ....


To put the UTF8 chars in strings is robust.

And even this is ok:

Code: Pascal  [Select][+][-]
  1. const
  2. hotlist ='☮±÷℃ ∫≦≧∞⨀⨌  ⟁ ⧉ ⇶⬣ ⬳ ◆☎☭☯♆♬⚓ ❎ 🚦😈 🤖 🧲 ⚽ 🌍 🍀 👀  🕘';
  3.  

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
Re: CASE from a control's Text property
« Reply #6 on: May 19, 2020, 09:45:07 pm »
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.

OK OK, I believe you :-)

Quote
And 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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2357
Re: CASE from a control's Text property
« Reply #7 on: May 19, 2020, 10:55:02 pm »
Hi

To make twiddling easier:

Code: Pascal  [Select][+][-]
  1. const A : array[0..7] of string[4] = (
  2.                    '↑','↗','→','↘','↓','↙','←','↖');  
[/size]

Winni

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
Re: CASE from a control's Text property
« Reply #8 on: May 23, 2020, 10:30:04 pm »
Code: Pascal  [Select][+][-]
  1. const A : array[0..7] of string[4] = (
  2.                    '↑','↗','→','↘','↓','↙','←','↖');  
[/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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

winni

  • Hero Member
  • *****
  • Posts: 2357
Re: CASE from a control's Text property
« Reply #9 on: May 24, 2020, 12:19:25 am »
Hi!

Okay - if you want to waste bytes then use instead of string[4]
TUTF8Char - that is string[7].

Winni


 

TinyPortal © 2005-2018