Search code examples
delphidelphi-7delphi-xe4

Difference between string[80] and string in Delphi 7 and Delphi XE4


I am migrating a delphi 7 application to delphi XE4. In Delphi 7, some variables are declared like this:

var abc : string[80];

While migrating this code, I am changing above code declaration as

var abc : string;

As per my understanding, string[80] is ansistring and string is unicode. So, is it right way to do it?

I am following the below link from stackoverflow:

Convert Char into AnsiChar or WideChar (Delphi)


Solution

  • Indeed you are correct:

    • string[#] are subtypes of ShortString.
      It has a maximum of 255 characters (depending on the #), and the encoding is undetermined (i.e. up to you).
    • string is a regular string, which was single-byte (now called AnsiString) up until Delphi 2007, and multi-byte (now called UnicodeString) as of Delphi 2009.
      Until Delphi 2007, the encoding is undetermined. As of Delphi 2009, both AnsiString and UnicodeString can have an encoding.

    More background information can be found in these two Delphi documentation topics:

    Answering your question about how you should replace ShortString:

    It totally depends on how you used your ShortString in Delphi 7. Depending on the use, there are multiple ways to go:

    • string
    • arrays of byte
    • AnsiString

    That all depends on the kind of data you are storing, so that is the first thing you need to find out.