Delphi XE - storing an AnsiChar in a String

I need to store an Ansi character (something between #32 and #255) in a string 
(UnicodeString, it's Delphi XE). And storing this character fails on Windows XP, 
while it works on Win7.

To duplicate the problem, run the following program, compiled with Delphi XE on 
Win7 and Windows XP:

procedure TForm6.Button1Click(Sender: TObject);
var
   s: string;
   i: integer;
begin
   s := AnsiChar(252);
   showmessage(s + ' ' + inttostr(ord(s[1])));  //result: 252

   i := 252;
   s := AnsiChar(i);
   showmessage(s + ' ' + inttostr(ord(s[1])));  //result: 1100 on XP, 252 on Win7
end;


Most of the characters work, but some characters - like #252 - do not. I haven't 
found a way to assign it properly when running XP.

Alexander Halser
0
Alexander
7/15/2011 9:03:09 PM
embarcadero.delphi.rtl 934 articles. 0 followers. Follow

2 Replies
1393 Views

Similar Articles

[PageSpeed] 23
Get it on Google Play
Get it on Apple App Store

"Alexander Halser" <nomail@ec-software.com> wrote in message 
news:378274@forums.embarcadero.com...

> I need to store an Ansi character (something between #32
> and #255) in a string (UnicodeString, it's Delphi XE). And
> storing this character fails on Windows XP, while it works
> on Win7.

Interpretaton of Ansi constants above #127 at compile-time is subject to the 
compiler's HIGHCHARUNICODE and CODEPAGE settings.  Setting HIGHCHARUNICODE 
to ON/OFF changes how constants #128-#255 are stored in the executable's 
resource data (and the CODEPAGE setting controls how they are encoded if 
they are not stored as-is), and has no effect on runtime values, such as 
your type-casted integer.  Those assignments are always subject to the OS's 
default Ansi codepage instead, which may be different on different Windows 
installations.

-- 
Remy Lebeau (TeamB)
0
Remy
7/15/2011 10:21:56 PM
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:378299@forums.embarcadero.com...

> Interpretaton of Ansi constants above #127 at compile-time is subject to 
> the compiler's HIGHCHARUNICODE and CODEPAGE settings.  Setting
> HIGHCHARUNICODE to ON/OFF changes how constants #128-#255
> are stored in the executable's resource data (and the CODEPAGE setting
> controls how they are encoded if they are not stored as-is), and has no 
> effect
> on runtime values, such as your type-casted integer.  Those assignments 
> are
> always subject to the OS's default Ansi codepage instead, which may be
> different on different Windows installations.

If you want to store Ansi #252 as Unicode #252 at compile-time, then try 
this:

{code:delphi}
procedure TForm6.Button1Click(Sender: TObject);
var
  s: String;
begin
  {$HIGHCHARUNICODE ON}
   s := AnsiChar(252);
  ShowMessage(s + ' ' + IntToStr(Ord(s[1])));
end;
{code}

Or:

{code:delphi}
procedure TForm6.Button1Click(Sender: TObject);
var
  s: String;
begin
   s := Char(252);
  ShowMessage(s + ' ' + IntToStr(Ord(s[1])));
end;
{code}

If you want to store Ansi #252 as Unicode #252 at run-time, then try this:

{code:delphi}
procedure TForm6.Button1Click(Sender: TObject);
var
  s: String;
  i: Integer;
begin
  i := 252;
  s := Char(i);
  ShowMessage(s + ' ' + IntToStr(Ord(s[1])));
end;
{code}

See the following discussion for more details on how the compiler handles 
Ansi character constants in relation to the HIGHCHARUNICODE directive:

    https://forums.embarcadero.com/thread.jspa?threadID=48722

-- 
Remy Lebeau (TeamB)
0
Remy
7/15/2011 10:36:52 PM
Reply:

Similar Artilces:

Delphi 5 (string[80]) vs Delphi XE
Hi guys i'm trying to convert a old application made with Delphi 5 to Delphi XE 5 The probleme i have right now is about String[80] and the Read / Write procedure i have a type like that Type TEnrMess = record Mess : String[80]; MessSuiv : Word; Hint : Word; end; And i read/write this type to a File of TEnrMess My probleme is that the string have changed from Delphi 5 to Delphi XE i join the link of a simple of the probleme that can be compiled on delphi 5 and any Delphi XE https://mega.co.nz/#!wV1VyZzY!1ha5oOxTg7L1WJAOXutUygkj...

Delphi XE convert string character to Ansichar
Hi Is there a function for converting a character in a string (unicode) to an ansichar. I am upgrading some very old programs to XE that work with characters and their ordinal values. I have just been type casting them with ansistring or ansichar, but some characters are giving incorrect results. For example var s : string; begin s := '€'; // character is hex 80 or 128 decimal showmessage(inttostr(ord(s[1]))); showmessage(inttostr(ord(ansichar(s[1])))); The above give two different answers (I can understand the first), but not why the second gives the inc...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

Delphi 2007 RTL in Delphi 7
I read somewhere that it is possible to use Delphi 2007's (or for that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the source of RTL. Is this really possible? What are the benefits that we can derive using a higher version's RTL? TIA Yogi Yang Yogi Yang wrote: > I read somewhere that it is possible to use Delphi 2007's (or for > that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the > source of RTL. If it actually compiles in Delphi 7, I guess it would be possible. OTOH, if one has Delphi 2007 already, I don't s...

Error on Delphi 6 but not on Delphi Xe for Ftp
I am Experimenting with get a file from our webside server via Ftp. I have 2 Machines 1 a laptop runing XP Delphi 6 Indy 10.5.8.0 An a machine runing Window 7 Delphi XE2 with Indy 10.5.8.0. I am using the Same Code on Both. procedure TFrmMain.ProcessItemDalySpecial; var PathDest : String; FileName : String; begin with FrmTb2 do begin if ReadIniBoolean(IniCfg,'FTP','UseFtpDaly') then begin Ftp.Host := ReadIniStr(IniCfg,'FTP','HostDaly'); Ftp.Port := ReadIniInt(IniCfg,'FTP'...

Migrate from Delphi 2007 for Win32 to Delphi XE
we use Delphi 2007 for Win32 to support legacy (32Bit) OWL-based pascal applications (yes i know it was a mistake not to switch to VCL 15 years ago). could our applications still be opened and compiled with Delphi XE? The existing projects are all plain Pascal-Code, coming back from the times of Turbo Pascal for Windows and later on Borland Pascal. Are there any improvements we could profit from (i.e IDE, Debugger)? Thanks Andrej > {quote:title=Andrej Dimic wrote:}{quote} > could our applications still be opened and compiled with Delphi XE? I'm not sure, but I guess ...

Migrating to Delphi XE from Delphi 7.0
Below is my code in Delphi 7.0, this is how to call another units in webmodule... Hello All, I create a web application in Delphi 7.0, using the Web Server Application, CGI, IntraWeb 7.0.15. And I used TIWPageProducer to view like this url "http://localhost/mcr/mcr.exe/main". I built and run. I viewed in thru IIS and it is running... This is my code in Delphi 7.0 .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1....

Migrating to Delphi XE from Delphi 7.0
Below is my code in Delphi 7.0, this is how to call another units in webmodule... Hello All, I create a web application in Delphi 7.0, using the Web Server Application, CGI, IntraWeb 7.0.15. And I used TIWPageProducer to view like this url "http://localhost/mcr/mcr.exe/main". I built and run. I viewed in thru IIS and it is running... This is my code in Delphi 7.0 .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end;...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

Any difference between Delphi Prism 2011 and Delphi Prism XE?
Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. Thanks, Hi Dan, > Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. See http://w...

Delphi 7.0 code convert to delphi XE ...
Hello All, I create an application using Web Server Application then CGI stand alone... In WebModule I add ModuleController component and IWPageProcedure... Below is my code in Delphi 7.0, this is how to call another units in webmodule... .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1.proLogInGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmLogIn.Create(AWebA...

Migrating from Delphi 6 to Delphi XE 3! [Edit]
All, I am a Delphi developer working in an windows form application developed using Delphi 6. Now, we are planning to upgrade the development tool. Can anyone provide me information related to major roadblocks that we can face while migrating from Delphi 6 to Delphi XE 3? Should we migrate to Delphi XE 3 or any other preferred version of Delphi based on the fact that our target users will be using Windows 7 or Windows 8? Do we have any tools or utilities to migrate the source code from Delphi 6 to higher version of Delphi? Also, any suggestions related to best practices are welcome....

Delphi XE and RTL makefile
In Delphi 2009 and 2010 there is a makefile in the source/win32/rtl. This makefile makes it possible to rebuild the RTL, e.g. if you have to fix a bug somewhere. In Delphi XE we notice that this file is no longer present. Is there a good explaination to this? Anders Evensen wrote: > In Delphi 2009 and 2010 there is a makefile in the source/win32/rtl. > This makefile makes it possible to rebuild the RTL, e.g. if you have > to fix a bug somewhere. In Delphi XE we notice that this file is no > longer present. Is there a good explaination to this? I can only tell you what I ...

Migration from Delphi 2007 Rad to Delphi XE Where is Quickreports
Have installed and finally registered Delphi Xe, I am looking for Quickreports but am unable to find it anywhere, I asked the Distributer and was told its packaged in Delphi XE, Well I should have gone to specsavers......cos I cant see it any where ? > {quote:title=Colin Coleman wrote:}{quote} > Have installed and finally registered Delphi Xe, I am looking for Quickreports but am unable to find it anywhere, I asked the Distributer and was told its packaged in Delphi XE, Well I should have gone to specsavers......cos I cant see it any where ? Hello Colin, Delphi X...

Web resources about - Delphi XE - storing an AnsiChar in a String - embarcadero.delphi.rtl

Unofficial ByteStrings Patch To Enable AnsiString Support In Delphi XE8 Firemonkey On Android And IOS ...
Developer Andreas Hausladen has released an updated version of his patch for System.ByteStrings which gives you access to PAnsiChar and other ...

Reference for unit 'System': Types
... Classes ][ Procedures and functions ][ Variables ][ Index ] Reference for unit 'System' ( #rtl ) Reference for unit 'System': Types AnsiChar ...

Use AnsiString And UTF8String In Delphi XE5 Firemonkey On Android And IOS
Embarcadero disabled access to byte stings in Delphi XE5 Firemonkey and if you're a long time Delphi developer you may be missing them. They ...

Free Pascal : Reference guide.
Contents List of Tables About this guide Notations Syntax diagrams About the Pascal language 1 Pascal Tokens 1.1 Symbols 1.2 Comments ...

Contents
1 Pascal Tokens 1.1 Symbols 1.2 Comments 1.3 Reserved words 1.3.1 Turbo Pascal reserved words 1.3.2 Free Pascal reserved words 1.3.3 Object ...

Resources last updated: 2/5/2016 8:23:04 PM