Quick start manual

Data types, variables, and constants
5-17
Structured types
•PChar(S) always returns a pointer to a memory block; if S is empty, a pointer to #0
is returned.
When you cast a long-string variable to a pointer, the pointer remains valid until
the variable is assigned a new value or goes out of scope. If you cast any other
long-string expression to a pointer, the pointer is valid only within the statement
where the typecast is performed.
When you cast a long-string expression to a pointer, the pointer should usually be
considered read-only. You can safely use the pointer to modify the long string
only when all of the following conditions are satisfied.
The expression cast is a long-string variable.
The string is not empty.
The string is unique—that is, has a reference count of one. To guarantee that the
string is unique, call the SetLength, SetString, or UniqueString procedure.
The string has not been modified since the typecast was made.
The characters modified are all within the string. Be careful not to use an out-of-
range index on the pointer.
The same rules apply when mixing WideString values with PWideChar values.
Structured types
Instances of a structured type hold more than one value. Structured types include
sets, arrays, records, and files as well as class, class-reference, and interface types. (For
information about class and class-reference types, see Chapter 7, “Classes and
objects.” For information about interfaces, see Chapter 10, “Object interfaces”).
Except for sets, which hold ordinal values only, structured types can contain other
structured types; a type can have unlimited levels of structuring.
By default, the values in a structured type are aligned on word or double-word
boundaries for faster access. When you declare a structured type, you can include the
reserved word packed to implement compressed data storage. For example,
type TNumbers = packed array[1..100] of Real;
Using packed slows data access and, in the case of a character array, affects type
compatibility (for more information, see Chapter 11, “Memory management”).