Quick start manual

12-2
Delphi Language Guide
Parameters and function results
A long-string or dynamic-array parameter is passed as a 32-bit pointer to the
dynamic memory block allocated for the long string. The value nil is passed for an
empty long string.
A pointer, class, class-reference, or procedure-pointer parameter is passed as a 32-
bit pointer.
A method pointer is passed on the stack as two 32-bit pointers. The instance
pointer is pushed before the method pointer so that the method pointer occupies
the lowest address.
Under the register and pascal conventions, a variant parameter is passed as a
32-bit pointer to a Variant value.
Sets, records, and static arrays of 1, 2, or 4 bytes are passed as 8-bit, 16-bit, and
32-bit values. Larger sets, records, and static arrays are passed as 32-bit pointers to
the value. An exception to this rule is that records are always passed directly on
the stack under the cdecl, stdcall, and safecall conventions; the size of a record
passed this way is rounded upward to the nearest double-word boundary.
An open-array parameter is passed as two 32-bit values. The first value is a pointer
to the array data, and the second value is one less than the number of elements in
the array.
When two parameters are passed on the stack, each parameter occupies a multiple of
4 bytes (a whole number of double words). For an 8-bit or 16-bit parameter, even
though the parameter occupies only a byte or a word, it is passed as a double word.
The contents of the unused parts of the double word are undefined.
Under the pascal, cdecl, stdcall and safecall conventions, all parameters are passed
on the stack. Under the pascal convention, parameters are pushed in the order of
their declaration (left-to-right), so that the first parameter ends up at the highest
address and the last parameter ends up at the lowest address. Under the cdecl,
stdcall, and safecall conventions, parameters are pushed in reverse order of
declaration (right-to-left), so that the first parameter ends up at the lowest address
and the last parameter ends up at the highest address.
Under the register convention, up to three parameters are passed in CPU registers,
and the rest (if any) are passed on the stack. The parameters are passed in order of
declaration (as with the pascal convention), and the first three parameters that
qualify are passed in the EAX, EDX, and ECX registers, in that order. Real, method-
pointer, variant, Int64, and structured types (see “Structured types” on page 5-17 do
not qualify as register parameters, but all other parameters do. If more than three
parameters qualify as register parameters, the first three are passed in EAX, EDX,
and ECX, and the remaining parameters are pushed onto the stack in order of
declaration. For example, given the declaration
procedure Test(A: Integer; var B: Char; C: Double; const D: string; E: Pointer);
a call to Test passes A in EAX as a 32-bit integer, B in EDX as a pointer to a Char, and
D in ECX as a pointer to a long-string memory block; C and E are pushed onto the
stack as two double-words and a 32-bit pointer, in that order.