String
From Delphi
'String is the representation of a sequence of characters (Chars). It is represented between single quotes. It can also be contatenated with +
[edit] Example
var MyString: String; begin MyString := 'Hello'; MyString := MyString + ' World'; end;
[edit] String Types
- ShortString (255 characters, up to 256 bytes of memory)
- AnsiString (also called LongString) (~2^31 characters, up to to 2GB of memory)
- WideString (~2^30 characters, up to 2GB of memory)
AnsiString is the current default for String, this will change in Delphi 2008, as Unicode will be enabled on the entire VCL
[edit] Notes (from the Newsgroups)
In a recent newsgroup discussion (comp.lang.pascal.delphi.misc early 2007), the question was raised how many stringtypes delphi has.
The one asking of course (me) knew there were more than the usual one-three that are usually named; short,ansi and widestring.
Note that in the summary below one can argue about the exact definition of a stringtype or if a certain entry counts as 1 or 255 (e.g. since shortstrings of a certain length are incompatible with eachother in some ways, one could say there are 255 shortstring types).
This however was not the purpose of the discussion. The purpose of the discussion is to make people aware about the vast amounts of stringtypes and conversions between them that exist in Delphi.
The original definition of a string type is: "Delphi string types and types that auto converted to them in some form or the other"
The list is:
- 3 short,ansi,widestring types.
- 1 (ansi)char
- 1 wide char, (both = resp. char and widechar from now on)
- 2 (static) array of both
- 2 dynamic array of both.
- 2 open array of both,
- 2 pointer to both,
- 2 pointer to array of both ,
1 open array shortstring. (in some semantic contexts different)
16 ->Theoretic maximal number of conversions: 16*16 = 256
This is way too high of cousre:
- assumes every conversion is possible (some like open arrays are possibly readonly),
- assumes very conversion reversable.
- also 16 direct assignments to same type are included, which are less prone to automatic
conversion problems.
Some other remarks gathered from the various comments (IRC and c.l.p.delphi.misc)
- Note that this even does not include some of these types in variants.
- multibyte forms in existing stringtypes are not counted.
- literals. Are string literals different ?
- Are there more types of literals? (resourcestring a separate kind?)
- are there conversions, not over the base string types between literals and e.g. static array of char?
The original list was created in a discussion about adding a new feature to FPC (and he also wanted to propose it to the Delphi devels). Among others, the "feature" added an autoconversion to strings. We asked "which string?". He answered "all of them".....


