Difference between revisions of "String"
Line 21: | Line 21: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
{$H+} // String is an alias for AnsiString | {$H+} // String is an alias for AnsiString | ||
− | + | var | |
name : String[25]; // name is a ShortString variable since a length specification overrides the alias setting | name : String[25]; // name is a ShortString variable since a length specification overrides the alias setting | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
In the future there may be a compiler directive to set String to refer to a Unicode string type (UTF-8 or UTF-16). | In the future there may be a compiler directive to set String to refer to a Unicode string type (UTF-8 or UTF-16). | ||
− | == | + | ==String types== |
− | The potential alias types for String - ShortString and | + | The potential alias types for String - ShortString, AnsiString, WideString and UnicodeString - differ with respect to ''length'' and //content'': |
− | + | *[[ShortString]] as a ''fixed maximum length'' that is decided by the programmer (e.g. ''name : String[25];'') but is limited to 255 characters. If a ShortString length is not explicitly given, then the length is implicitly set to 255. | |
− | *ShortString | + | *[[AnsiString]] has a ''variable length'' that is limited only by the value of High(SizeInt) (which is platfom dependant) and available memory. |
− | + | *[[WideString]] is similar to AnsiString but contains [[WideChar]] instead of [[Char]] | |
− | *AnsiString has a ''variable length'' that is limited only by the value of High(SizeInt) (which is platfom dependant) and available memory. | + | *[[UnicodeString]] is similar to AnsiString but contains [[UnicodeChar]] instead of [[Char]] |
== See also == | == See also == |
Revision as of 00:36, 16 September 2016
│
Deutsch (de) │
English (en) │
español (es) │
français (fr) │
русский (ru) │
String is a type which may contain characters.
Alias
String is an alias for ShortString or AnsiString depending on a compiler setting.
If compiler directive {$H} or compiler directive {$LongStrings} has been used with an "on" parameter ( {$H+} or {$LongStrings ON} ), then a String type is the same as an AnsiString type, if not ( {$H-} or {$LongStrings OFF} ), it is a ShortString type. What String is an alias for can also be set by the -Sh command line option.
NOTE: The {$mode} compiler directive will also set the String alias. After the compiler mode is set to FPC (the default), ObjFPC, MacPAS or TP, String will be an alias for ShortString. After the compiler mode is set to Delphi, String will be an alias for AnsiString. So the String alias setting should be made following the compiler mode setting to prevent it from being overridden:
{$H+} // String is an alias for AnsiString
{$mode ObjFPC} // also affects String alias - String is now an alias for ShortString
{$H+} // String is now an alias for AnsiString
A String variable declared with a length specifier will always be a ShortString regardless of the compiler setting for String alias.
{$H+} // String is an alias for AnsiString
var
name : String[25]; // name is a ShortString variable since a length specification overrides the alias setting
In the future there may be a compiler directive to set String to refer to a Unicode string type (UTF-8 or UTF-16).
String types
The potential alias types for String - ShortString, AnsiString, WideString and UnicodeString - differ with respect to length and //content:
- ShortString as a fixed maximum length that is decided by the programmer (e.g. name : String[25];) but is limited to 255 characters. If a ShortString length is not explicitly given, then the length is implicitly set to 255.
- AnsiString has a variable length that is limited only by the value of High(SizeInt) (which is platfom dependant) and available memory.
- WideString is similar to AnsiString but contains WideChar instead of Char
- UnicodeString is similar to AnsiString but contains UnicodeChar instead of Char
See also
- Character and string types, a detailed reference covering internal memory layout and access options.
simple data types |
|
---|---|
complex data types |