Name
ShortString Type
Syntax
type ShortString; typeName= string[Constant];
Description
A ShortString is a counted string with a maximum
length of 255 characters. You can declare a short string with the
ShortString type or with the
string keyword and a maximum length. The maximum
length must be a constant expression in the range
to 255. If you use the $H or
$LongStrings compiler directive, you can change a
plain use of the string keyword to mean
ShortString instead of the default
AnsiString.
Delphi stores a short string as a character array with a reserved byte to store the string’s length. If you take the address of a short string, Delphi returns a pointer to the length byte.
Tips and Tricks
As with all strings in Delphi, string indices start at 1, but you can also refer to element of a short string, which returns the length, as a
Char. Instead of referring to the zeroth element, though, you should use theLengthfunction andSetLengthprocedure to get or set the string’s length.Most strings in new Delphi programs use the more convenient
AnsiStringtype, but short strings are useful for reading and writing data. See theFilekeyword for an example.
See Also
| AnsiString Type, File Keyword, Length Function, SetLength Procedure, SetString Procedure, String Keyword, WideString Type, $H Compiler Directive, $LongStrings Compiler Directive |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access