You may often use AnsiString for strings with object pascal, but other strings are generally rarely used.
Here are a few types of strings:
AnsiSring This is Pascal's default type. There is no limit to its length. And the string ends with null. That is, it ends with '/0'.
ShortSring is for compatibility with previous versions of Delphi. Its length is limited to 255 characters.
WideSring is similar to AnsiString, but it is composed of WideChar characters.
PChar Pointer to a null-terminated string. Similar to char* or lpstr in c.
PAnsiChar points to a null-terminated AnisChar-terminated string pointer.
PWideChar Pointer to a null-terminated String of WideChar.
By default it is of type AnisSring:
var
S:String;
It is also possible to have the compiler switch $H to define the String type as ShortString type: example
var
{$H-}
s1:=string;//s1 is shortstring type
{$H+}
s2:=string;//s2 is sring type
But when the length of the specified string is less than 255, {$H} is always AnsiSring.
example:
var
s:string[254];
Below I will talk about the respective usage of these types:
1. AnisSring type
It is dynamically allocated and has automatic recycling. This feature is called lifetime self-management. No need for intermediate results like in c
Since the AnisSring type string is null-terminated, it is compatible with Win32Api. Actually AnisSring is
pointer to a string structure on the stack