"string[1];" always reserves 256 bytes (the max size of a shortstring is 255
characters + 1byte for length) and is in fact an ansistring

So assigning a char(which is really a widechar in Delphi XE2) to an
ansistring/ansichar won't work without losing some information. I kind of
expected the compiler to return a warning about implicit type conversion
rather than a compilation error, but then again shortstrings are a legacy of
Delphi 1.0 (16 bit applications)  and can't expect things to be supported
forever. There is no point in using shortstrings anymore nowadays - just
replace all your shortstrings with normal strings in your code.


{$IFDEF UNICODE} Is automatically defined since delphi 2009 - it's a flag to
say that strings are now widestrings.


Kind Regards,
Stefan Mueller 
_______________________
R&D Manager
ORCL Toolbox LLP, Japan
http://www.orcl-toolbox.com


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of John Bird
Sent: Tuesday, January 17, 2012 3:29 PM
To: [email protected]; NZ Borland Developers Group - Delphi List
Subject: [DUG] [computing]XE2 string conversion question

I am tidying up some library stuff for XE2....

Assigning a AnsiChar to Char does not compile in this case below

Background - from what I have read not all variables declared string are
compiled as string in XE2 - for instance any sized strings as in the record
below are take to be AnsiString.

(I am also wondering if this applies to Dataset string fields, which are
often declared with a length)

To save me time in testing and experimenting and googling, which conversions
do work implicitly by assignment, and which do not?

Anyone who has already been there and done that suggest best practice for
this case?

type
  TJUFRec = record
    JUFno:integer;
    JUFName:string[20];
    JUFHeds:string[10];
    JUFPrompt:string[30];
    JUFArrNo:integer;
    JUFArrSz:integer;
    JUFType1:string[1];        //<===Ansistring
    JUFNB:integer;
    JUFType2:string[10];
    JUFSB:integer;
    JUFDecpl:integer;
    JUFUpc:integer;
    JUFMin:int64;
    JUFMax:int64;
    JUFReq:integer;
    JUFEdtName: string[25];
    JUFEdit:integer;
    JUFShow:integer;
    JUFRemake:integer;
    JUFDesc:string[60];
  end;

var
lJUFType1:char;

begin
//
  lJUFType1:=aJUFRec.JUFType1[1];        //<======== does not compile

error is [DCC Error]  E2010 Incompatible types: 'Char' and 'AnsiChar'



John Bird
JBCL
Contact:
[email protected]
[email protected]
(027 4844528)
http://www.jbcl.co.nz
http://jbclnz.googlepages.com



_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: [email protected]
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [email protected] with 
Subject: unsubscribe

Reply via email to