I am trying to migrate a project from Delphi 4 to Delphi XE2. I have a requirement to use shortstring in a project. According to Delphi's help, $ H- should force the compiler to use short lines for type string . I used this directive, but I do not see any difference. I wrote 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 str and short , because the compiler should be considered as shortstring . But size 4 for str and 256 for short . Is there any other way for the compiler to treat string as a shortstring or is it the only solution to replace all occurrences of string with shortstring in the source code?
source share