Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-07

2.5.1: Ansi string constants vs Unicode

6 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tobias Giesen

Hello,

I've got 2.5.1 now. I have a string constant like this:

const Vec:AnsiString=#$094#$06D;

This should just be 8-bit data with no conversion.

But I get
"Error: Unicodechar/string constants cannot be converted to ansi/shortstring at compile-time."

Can I tell the compiler to interpret all string constants as Ansi rather than Unicode?

I read the FPC UNICODE SUPPORT wiki page but it doesn't go into such detail.

Kind Regards,
Tobias Giesen

Super Flexible Software Ltd. & Co. KG
Lessingstr. 42
48485 Neuenkirchen, Germany
www.superflexible.com
www.tgtools.com

----------------------------------------------------------- Registered at register court Steinfurt as HRA 5061 Liability / general partner: TGTools Ltd.
Company No. 05513299
Registered in England and Wales
Directors: Tobias Giesen and Claudia Giesen

dmitry boyarintsev
to Tobias Giesen
Tobias Giesen wrote 5 lines
I've got 2.5.1 now. I have a string constant like this: const Vec:AnsiString=#$094#$06D; This should just be 8-bit data with no conversion.
try const Vec:AnsiString=#$94#$6D;

thanks,
dmitry

Martin
to Jonas Maebe: I've now documented this change at http://wiki.freepascal.org/User_Changes_Trunk#Short.2FA…
Jonas Maebe wrote 8 lines
>> const Vec:AnsiString=#$094#$06D; >> This should just be 8-bit data with no conversion. >> > try const Vec:AnsiString=#$94#$6D; > I've now documented this change at http://wiki.freepascal.org/User_Changes_Trunk#Short.2FAnsistring_typed_constants_containing_widechars.2Funicodechars

from the page:

{$codepage utf8}
const
   s1: shortstring = 'éà';
   s2: ansistring = #$094#$06D;
   s3: ansistring = #267#543;

In case of s2, s3 it's a do-able conversion, since the numeric values are already known.

But with s1 that could potentially be much much more work, and also very inconvenient for writing new code. I would not know all the ordinal values from the top of my head, and if the string was long, it would mean to look up dozens of uni-codes.

It would be nice if there was(maybe there is) some way, of telling the compiler that the string is to be treaded as binary-data. Maybe like:

{$codepage utf8}
const
{$codepage binary} // temporary change
   s1: shortstring = 'éà';
{$codepage utf8} // back to original
  s2: ansistring = #$094#$06D;
  s3: ansistring = #267#543;
Jonas Maebe
to Martin
Martin wrote 9 lines
It would be nice if there was(maybe there is) some way, of telling the compiler that the string is to be treaded as binary-data. Maybe like: {$codepage utf8} const {$codepage binary} // temporary change s1: shortstring = 'éà'; {$codepage utf8} // back to original s2: ansistring = #$094#$06D; s3: ansistring = #267#543;

No, that is not possible. A file always has only one code page.

If you want the compiler not to interpret any of the character literals, you can do so by not using any {$codepage xxx} directive (and not including any BOM either). Then you can save the file in your editor using any code page you want, and the compiler will treat the characters as sequences of byte literals.

Jonas