Recent

Author Topic: [SOLVED] Assigning a literal value to a Char typed constant...  (Read 1570 times)

GypsyPrince

  • Guest
This constant declaration as String type using a literal value works (for me).
 
Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 : String = '╞';

However, this declaration as Char type using a literal does not work.

Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 : Char = '╞';

Now... this decalaration without typing using a literal does work.

Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 = '╞';

So, am I to surmise from this experiment that I can assign literal values to String typed constants, but not to Char typed constants? Or, am I just declaring this totally wrong?

The following method works (partially)...

Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 = #198;

This last declaration does not produce an error, but it does not give me the same wide character (╞) as does using the literal. It gives me a character which equates to Chr(198) when I need the one which equates to ChrW(198).

Any thoughts on what I might possibly be doing incorrect here?
« Last Edit: April 05, 2020, 11:05:18 pm by GypsyPrince »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Assigning literal values to constants...
« Reply #1 on: April 05, 2020, 09:43:19 pm »
Hi!



is   Codepoint  U+255E
Hex = E2959E
Decimal = 14849438

Lazarus is UTF8!

Winni

GypsyPrince

  • Guest
Re: Assigning a literal value to a Char typed constant...
« Reply #2 on: April 05, 2020, 10:04:43 pm »
@winni

Quote


is   Codepoint  U+255E
Hex = E2959E
Decimal = 14849438

Lazarus is UTF8!

Ah, that makes complete sense.

I think I remember from an earlier discussion about assigning hexadecimal values to constants.
Am I remembering this correctly?

Using "Const DWG_ALT198 = '╞';" works well enough for me.  But just for curiosity's sake, can I assign this value to a Char typed constant using a hexadecimal value? Something similar to:

Quote
Const DWG_ALT198 : Char = Hex(198);

This last statement won't work, but is just a visual example to clarify what I am asking. Again, this is only experimentation and testing Pascal's boundaries. So, it may not actually be worth putting a lot of thought into.
« Last Edit: April 05, 2020, 10:21:52 pm by GypsyPrince »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Assigning a literal value to a Char typed constant...
« Reply #3 on: April 05, 2020, 10:40:28 pm »
Hi!

The correct way to assign a hex value to a byte /integer /word/ ....

is since decades

Code: Pascal  [Select][+][-]
  1. myByte = $FF;

which means 255 decimal.

You should not try to assign an UTF8-char to a char:
In the most cases it is longer than one byte.

I don't want to repeat the endless UTF8 discussions from some years ago, so here is a introduction about UTF8 and fpc/Lazarus:

https://wiki.freepascal.org/Unicode_Support_in_Lazarus

Winni


GypsyPrince

  • Guest
Re: Assigning a literal value to a Char typed constant...
« Reply #4 on: April 05, 2020, 11:04:33 pm »
Thanks for that info!!

Your are correct. The information at that link said I need to use a String type constant (or variable) with extended ASCII codes such as that character. It also said that a Char type could be forced to use them, but required a bit of effort and only works with MS Windows, which would not work with my goal of being cross-platform.

So... String type it is.
« Last Edit: April 06, 2020, 02:21:51 am by GypsyPrince »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: [SOLVED] Assigning a literal value to a Char typed constant...
« Reply #5 on: April 05, 2020, 11:16:16 pm »
If you want to have a look a the different code blocks of UTF8 then look at
https://www.utf8-chartable.de/unicode-utf8-table.pl

In the third row you got a comboBox with the different codeblocks - which is not so obvious due to bad HTML design.

Your "beloved " '╞' is in the block BoxDrawing, which is placed between U+2500 and U+257F.


Winni



lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Assigning a literal value to a Char typed constant...
« Reply #6 on: April 06, 2020, 09:12:33 am »
But just for curiosity's sake, can I assign this value to a Char typed constant using a hexadecimal value? Something similar to:

Quote
Const DWG_ALT198 : Char = Hex(198);

Yes, you can:
Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 : Char = #$C6;
or you can use the intrinsic Chr():
Code: Pascal  [Select][+][-]
  1. Const DWG_ALT198 : Char = Chr($C6);
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018