I'm trying to port a project from Delphi 4 to Delphi XE2. I have a requirement to use shortstring
in the project. According to the Delphi Help, $H- should make the compiler use shortstrings for the string
type. I've used this directive but I don't see any difference. I've written a small test program:
program Stringtest;
{$APPTYPE CONSOLE}
{$R *.res}
{$H- }
uses
System.SysUtils;
var
str : string;
short : shortstring;
begin
try
str := 'testing';
short := 'testing';
Writeln('str ' +Format('%d', [sizeOf(str)]) );
Writeln('short ' +Format('%d', [sizeOf(short)]) );
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
In my opinion the output should be the same for both str
and short
because the compiler should treat both as a shortstring
. But the size is 4 for str
and 256 for short
. Is there any other way to have the compiler treat string
as shortstring
or is the only solution to replace all occurences of string
with shortstring
in the source code?