Chapter 6. System Constants

This chapter is separate from Chapter 5, to make it easier to find the information you need. Instead of cluttering Chapter 5 with all the individual identifiers, this chapter organizes the system constants logically. All the constant literals described in this chapter are defined in the System unit, so they are available at all times.

Variant Type Codes

The VarType function returns the type code of a Variant. The type code is a small integer that contains a type identifier with the optional modifiers varArray and varByRef. Any type except varEmpty and varNull can have the varArray modifier. Delphi automatically takes care of the varByRef modifier. For more information, see the discussion of the Variant type in Chapter 5. Table 6-1 lists the type identifiers, and Table 6-2 lists the optional modifiers.

Table 6-1. Variant Type Identifiers

Literal

Value

Description

varEmpty

$0000

Variant not assigned

varNull

$0001

Null value

varSmallint

$0002

16-bit, signed integer

varInteger

$0003

32-bit, signed integer

varSingle

$0004

32-bit floating-point number

varDouble

$0005

64-bit floating-point number

varCurrency

$0006

64-bit fixed point number with four decimal places

varDate

$0007

64-bit floating-point date and time

varOleStr

$0008

#0-terminated wide string

varDispatch

$0009

IDispatch interface

varError

$000A

32-bit error code

varBoolean

$000B

Logical True or False

varVariant

$000C

Pointer to another Variant

varUnknown

$000D

IUnknown interface

varByte

$0011

8-bit, unsigned integer

varStrArg

$0048

Not used in Variants, but describes a string parameter to an IDispatch method

varString

$0100

Delphi AnsiString

varAny

$0101

Opaque pointer, used for CORBA Any values

varTypeMask

$0FFF

Mask to extract type identifier from VarType

Table 6-2. Variant Type Modifiers

Literal

Value

Description

varArray

$2000

Variant is an array.

varByRef

$4000

Additional level of indirection to access data.

Open Array Types

When a subroutine parameter is a variant open array (array of const), Delphi passes the array argument by converting each array element to a TVarRec record. Each record’s VType member identifies the member’s type. For more information, see the discussion of the array keyword in Chapter 5. Table 6-3 lists the VType values for a TVarRec record.

Table 6-3. Possible Values for TVarRec.VType

Literal

Value

Element Type

vtInteger

0

Integer
vtBoolean

1

Boolean
vtChar

2

Char
vtExtended

3

Extended
vtString

4

ShortString
vtPointer

5

Pointer
vtPChar

6

PChar
vtObject

7

TObject
vtClass

8

TClass
vtWideChar

9

WideChar
vtPWideChar

10

PWideChar
vtAnsiString

11

AnsiString
vtCurrency

12

Currency
vtVariant

13

Variant
vtInterface

14

IUnknown
vtWideString

15

WideString
vtInt64

16

Int64	

Virtual Method Table Offsets

Chapter 3, describes the format of a class’s virtual method table (VMT). Delphi does not provide a convenient record for accessing a VMT, but it does define the offsets (in bytes) of the various parts of a VMT. The offsets are relative to the class reference (TClass). Note that the offsets change from one version of Delphi to the next. Table 6-4 lists the offset names and values.

Table 6-4. Offsets in a Class’s Virtual Method Table

Literal

Value

Description

vmtSelfPtr

-76

Pointer to the start of the VMT

vmtIntfTable

-72

Pointer to the interface table

vmtAutoTable

-68

Pointer to the automation table

vmtInitTable

-64

Pointer to the initialization and finalization table

vmtTypeInfo

-60

Pointer to the class’s TTypeInfo record

vmtFieldTable

-56

Pointer to the published field table

vmtMethodTable

-52

Pointer to the published method table

vmtDynamicTable

-48

Pointer to the dynamic method and message table

vmtClassName

-44

Pointer to the class name as a ShortString

vmtInstanceSize

-40

Instance size in bytes

vmtParent

-36

Pointer to a pointer to the base class VMT

vmtSafeCallException

-32

Address of the SafeCallException method

vmtAfterConstruction

-28

Address of the AfterConstruction method

vmtBeforeDestruction

-24

Address of the BeforeDestruction method

vmtDispatch

-20

Address of the Dispatch method

vmtDefaultHandler

-16

Address of the DefaultHandler method

vmtNewInstance

-12

Address of the NewInstance method

vmtFreeInstance

-8

Address of the FreeInstance method

vmtDestroy

-4

Address of the Destroy destructor

Runtime Error Codes

Delphi does not export literals for its runtime errors. Instead, it defines a number of literals in the implementation section of the System and SysInit units, and other error codes are defined implicitly in the System code. For your convenience, the following tables list all the runtime error numbers that are built into Delphi’s System unit.

The internal error codes are used internally to the System unit. If you implement an ErrorProc procedure, these are the error codes you must interpret.

The ErrorProc procedure in the SysUtils unit maps internal error codes to exceptions. Table 6-5 lists the internal error codes and the exception class that the SysUtils unit uses for each error.

If you do not use the SysUtils unit, or if an error arises before the SysUtils unit is initialized or after it is finalized, the ErrorProc procedures in the System unit maps internal error codes to external error codes. Some memory and pointer errors do not produce immediate access violations, but instead corrupt memory in a way that does not let Delphi shut down cleanly. These errors often manifest themselves as runtime errors when the program exits. Table 6-6 lists the external error codes.

Table 6-7 lists the I/O error codes, which are reported with an internal error code of zero. Note that any Windows error code can also be an I/O error code. (SysUtils raises EInOutError for all I/O errors.)

Table 6-5. Internal Error Codes

Error Number

Description

SysUtils Exception Class

0

I/O error; see Table 6-7

EInOutError

1

Out of memory

EOutOfMemory

2

Invalid pointer

EInvalidPointer

3

Integer divide by zero

EDivByZero

4

Array bounds error

ERangeError

5

Integer or enumerated range error

EIntOverflow

6

Invalid floating-point operation

EInvalidOp

7

Floating-point divide by zero

EZeroDivide

8

Floating-point overflow

EOverflow

9

Floating-point underflow

EUnderflow

10

Invalid object type cast

EInvalidCast

11

Access violation

EAccessViolation

12

Stack overflow

EPrivilege

13

Control+Break interrupt

EControlC

14

Privileged instruction

EStackOverflow

15

Invalid Variant type cast

EVariantError

16

Invalid Variant operation

EVariantError

17

No Variant method call dispatcher

EVariantError

18

Unable to create Variant array

EVariantError

19

Array operation on a non-array Variant

EVariantError

20

Variant array bounds error

EVariantError

21

Assertion failed

EAssertionFailed

22

SysUtils external exception

EExternalException

23

Invalid interface type cast

EIntfCastError

24

Error in safecall method

ESafeCallException
Table 6-6. External Error Codes

Error Number

Description

200

Divide by zero

201

Array bounds error

202

Stack overflow

203

Out of memory

204

Invalid pointer

205

Floating-point overflow

206

Floating-point underflow

207

Invalid floating-point operation

210

Call to an abstract method

215

Integer or enumerated bounds error

216

Access violation

217

Unhandled exception

218

Privileged instruction

219

Invalid class type cast

220

Invalid Variant type cast

221

Invalid Variant operation

222

No Variant method call dispatcher

223

Unable to create Variant array

224

Array operation on a non-array Variant

225

Variant array bounds error

226

Cannot initialize thread local storage

227

Assertion failed

228

Invalid interface type cast

229

Error from a safecall method

Table 6-7. I/O Error Codes

Error Number

Description

100

Read past end of file.

101

Disk is full.

102

AssignFile has not yet been called.

103

The file is closed.

104

File not open for input.

105

File not open for output.

106

Incorrectly formatted input for Read.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset