Delphi 11 Define String Type ( ) vs [ ]

I'm using Delphi 11 to build TurboPower BTree Filer, which is supposed to support Delphi up to 2006 version. Since using newer version I have to convert Char to AnsiChar and String to AnsiString but this string type definition fails in Delphi 11:

  IsamFileNameLen = 64;

  IsamFileName = ansistring[IsamFileNameLen];

It doesn't like the square brackets, so I presume it wants parentheses (), but it didn't like those either?

What is the problem?

Edit: If it's just "string" then it is okay but it's not what I need, I need ansistring ?



  • It is true that string typically refers to AnsiString before D2009, and to UnicodeString since D2009. But, only when used as a dynamic long string . When used as a fixed-length short string instead, string still refers to an ANSI type. So, the correct declaration remains the same in all versions:

      IsamFileNameLen = 64;
      IsamFileName = string[IsamFileNameLen];

    This is described in Delphi's documentation:

    The Delphi language supports short-string types - in effect, subtypes of ShortString - whose maximum length is anywhere from 0 to 255 characters. These are denoted by a bracketed numeral appended to the reserved word string. For example:

    var MyString: string[100];

    creates a variable called MyString, whose maximum length is 100 characters. This is equivalent to the declarations:

    type CString = string[100];
    var MyString: CString;