Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə84/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   80   81   82   83   84   85   86   87   ...   294
DelphiLanguageGuide

Short Strings
A ShortString is 0 to 255 characters long. While the length of a ShortString can change dynamically, its memory is
a statically allocated 256 bytes; the first byte stores the length of the string, and the remaining 255 bytes are available
for characters. If 
S
 is a ShortString variable, 
Ord(S[0])
, like 
Length(S)
, returns the length of 
S
; assigning a value
to 
S[0]
, like calling 
SetLength
, changes the length of 
S
. ShortString is maintained for backward compatibility only.
The Delphi language supports short-string types - in effect, subtypes of ShortString - whose maximum length is
anywhere from 0 to 255 characters. These are denoted by a bracketed numeral appended to the reserved word
string. For example,
var MyString: string[100];
creates a variable called 
MyString
 whose maximum length is 100 characters. This is equivalent to the declarations
type CString = string[100];
var MyString: CString;
Variables declared in this way allocate only as much memory as the type requires - that is, the specified maximum
length plus one byte. In our example, 
MyString
 uses 101 bytes, as compared to 256 bytes for a variable of the
predefined ShortString type.
When you assign a value to a short-string variable, the string is truncated if it exceeds the maximum length for the
type.
The standard functions High and Low operate on short-string type identifiers and variables. High returns the
maximum length of the short-string type, while Low returns zero.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   80   81   82   83   84   85   86   87   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin