The ansistring is a dynamically allocated string which has no length limitation. When the string is no longer being referenced (its reference count reaches zero), its memory is automatically freed.
If the ansistring is a constant, then its reference count will be equal to -1, indicating that it should never be freed. The structure in memory for an ansistring is shown in table (8.3).
|-8||Longint with reference count.|
|-4||Longint with actual string size.|
|0||Actual array of char, null-terminated.|
A shortstring occupies as many bytes as its maximum length plus one. The first byte contains the current dynamic length of the string. The following bytes contain the actual characters (of type char) of the string. The maximum size of a short string is the length byte followed by 255 characters.
A widestring is allocated on the heap, much like an ansistring. Unlike the ansistring, a widestring takes 2 bytes per character, and is terminated with a double null.