Real Types

A real type defines a set of numbers that can be represented with floating-point notation. The table below gives the ranges and storage formats for the fundamental real types on the Win32 platform. Double -5.0 x 10A324 1.7 x 10A308 1516 8 Double -5.0 x 10A324 1.7 x 10A308 1516 8 Currency -922337203685477.5808 922337203685477.5807 1920 8 Currency -922337203685477.5808 922337203685477.5807 1920 8 The following table shows how the fundamental real types map to .NET framework types. Fundamental...

Control Loops

Loops allow you to execute a sequence of statements repeatedly, using a control condition or variable to determine when the execution stops. Delphi has three kinds of control loop repeat statements, while statements, and for statements. You can use the standard Break and Continue procedures to control the flow of a repeat, while, or for statement. Break terminates the statement in which it occurs, while Continue begins executing the next iteration of the sequence. The syntax of a repeat...

Instruction Opcodes

The built-in assembler supports all of the Intel-documented opcodes for general application use. Note that operating system privileged instructions may not be supported. Specifically, the following families of instructions are supported Pentium family Pentium Pro and Pentium II Pentium III Pentium 4 In addition, the built-in assembler supports the following instruction sets AMD 3DNow (from the AMD K6 onwards) AMD Enhanced 3DNow (from the AMD Athlon onwards) For a complete description of each...

Text File Device Drivers

You can define your own text file device drivers for your programs. A text file device driver is a set of four functions that completely implement an interface between Delphi's file system and some device. The four functions that define each device driver are Open, InOut, Flush, and Close. The function header of each function is function DeviceFunc(var F TTextRec) Integer where DeviceFunc is the name of the function (that is, Open, InOut, Flush, or Close). The return value of a deviceinterface...

Using the inline Directive

The Delphi compiler allows functions and procedures to be tagged with the inline directive to improve performance. If the function or procedure meets certain criteria, the compiler will insert code directly, rather than generating a call. Inlining is a performance optimization that can result in faster code, but at the expense of space. Inlining always causes the compiler to produce a larger binary file. The inline directive is used in function and procedure declarations and definitions, like...

Expression Types

Every built-in assembler expression has a typeor, more correctly, a size, because the assembler regards the type of an expression simply as the size of its memory location. For example, the type of an Integer variable is four, because it occupies 4 bytes. The built-in assembler performs type checking whenever possible, so in the instructions the assembler checks that the size of QuitFlag is one a byte , and that the size of OutBufPtr is two a word . The instruction produces an error because DL...

Method Resolution Clause

You can override the default name-based mappings by including method resolution clauses in a class declaration. When a class implements two or more interfaces that have identically named methods, use method resolution clauses to resolve the naming conflicts. A method resolution clause has the form procedure interface.interfaceMethod implementingMethod function interface.interfaceMethod implementingMethod where implementingMethod is a method declared in the class or one of its ancestors. The...

Automation Object Method Call Syntax

The syntax of an Automation object method call or property access is similar to that of a normal method call or property access. Automation method calls, however, can use both positional and named parameters. But some Automation servers do not support named parameters. A positional parameter is simply an expression. A named parameter consists of a parameter identifier, followed by the symbol, followed by an expression. Positional parameters must precede any named parameters in a method call....

Open Array Constructors

Open array constructors allow you to construct arrays directly within function and procedure calls. They can be passed only as open array parameters or variant open array parameters. An open array constructor, like a set constructor, is a sequence of expressions separated by commas and enclosed in brackets. you could call the Add procedure with the statement Open array constructors can be passed only as value or const parameters. The expressions in a constructor must be assignment-compatible...

Procedural Types

On the Win32 platform, a procedure pointer is stored as a 32-bit pointer to the entry point of a procedure or function. A method pointer is stored as a 32-bit pointer to the entry point of a method, followed by a 32-bit pointer to an object. On the .NET platform, procedural types are implemented using the System.MulticastDelegate class types. Class Types The following discussion of the internal layout of class types applies to the Win32 platform only. On the .NET platform, class layout is...

Variant Type Conversions

All integer, real, string, character, and Boolean types are assignment-compatible with Variant. Expressions can be explicitly cast as variants, and the VarAsType and VarCast standard routines can be used to change the internal representation of a variant. The following code demonstrates the use of variants and some of the automatic conversions performed when variants are mixed with other types. The compiler performs type conversions according to the following rules. converts to string...

Short String Types

A string occupies as many bytes as its maximum length plus one. The first byte contains the current dynamic length of the string, and the following bytes contain the characters of the string. The length byte and the characters are considered unsigned values. Maximum string length is 255 characters plus a length byte string 255 . Note On the .NET platform, the short string type is implemented as an array of unsigned bytes. Long String Types A long string variable occupies four bytes of memory...

Operator Precedence

In complex expressions, rules of precedence determine the order in which operations are performed. Precedence of operators , , div, mod, and, shl, shr, as second , lt gt , lt , gt , lt , gt , in, is fourth lowest An operator with higher precedence is evaluated before an operator with lower precedence, while operators of equal precedence associate to the left. Hence the expression multiplies y times z, then adds X to the result is performed first, because is has a higher precedence than . But...

Library Initialization Code

The statements in a library's block constitute the library's initialization code. These statements are executed once every time the library is loaded. They typically perform tasks like registering window classes and initializing variables. Library initialization code can also install an entry point procedure using the DllProc variable. The DllProc variable is similar to an exit procedure, which is described in Exit procedures the entry point procedure executes when the library is loaded or...

Array Constants

To declare an array constant, enclose the values of the array's elements, separated by commas, in parentheses at the end of the declaration. These values must be represented by constant expressions. For example, const Digits array 0 9 of Char '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' declares a typed constant called Digits that holds an array of characters. Zero-based character arrays often represent null-terminated strings, and for this reason string constants can be used to initialize...

Declaring and Accessing Nested Classes

The following examples demonstrate how to declare and access fields and methods of a nested class. myInnerField Integer procedure innerProc end To implement the innerProc method of the inner class, you must qualify its name with the name of the outer class. For example procedure TOuterClass.TInnerClass.innerProc begin To access the members of the nested type, use dotted notation as with regular class member access. For example x TOuterClass y TOuterClass.TInnerClass x TOuterClass.Create...

Calling Conventions

When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall. For example, function MyFunction X, Y Real Real cdecl Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register. The register and...

Forward Declarations and Mutually Dependent Classes

If the declaration of a class type ends with the word class and a semicolon - that is, if it has the form type className class with no ancestor or class members listed after the word class, then it is a forward declaration. A forward declaration must be resolved by a defining declaration of the same class within the same type declaration section. In other words, between a forward declaration and its defining declaration, nothing can occur except other type declarations. Forward declarations...

Special Symbols

Special symbols are non-alphanumeric characters, or pairs of such characters, that have fixed meanings. The following single characters are special symbols amp ' , - . lt gt The following character pairs are also special symbols . . lt gt lt gt The following table shows equivalent symbols The left bracket is equivalent to the character pair of left parenthesis and period . The right bracket is equivalent to the character pair of period and right parenthesis . The left brace is equivalent to the...

Comments and Compiler Directives

Comments are ignored by the compiler, except when they function as separators delimiting adjacent tokens or compiler directives. There are several ways to construct comments Text between a left brace and a right brace constitutes a comment. Text between a left-parenthesis-plus-asterisk and an asterisk-plus-right-parenthesis is also a comment Any text between a double-slash and the end of the line constitutes a comment. Comments that are alike cannot be nested. For instance, will not work, but...

Package Declarations and Source Files

Each package is declared in a separate source file, which should be saved with the .dpk extension to avoid confusion with other files containing Delphi code. A package source file does not contain type, data, procedure, or function declarations. Instead, it contains a list of other packages required by the new package. These are packages to which the new package is linked. a list of unit files contained by, or bound into, the package when it is compiled. The package is essentially a wrapper for...

Compiling Packages

Packages are ordinarily compiled from the IDE using .dpk files generated by the Project Manager. You can also compile .dpk files directly from the command line. When you build a project that contains a package, the package is implicitly recompiled, if necessary. The following table lists the files produced by the successful compilation of a package. Compiled package files File extension Contents DCP Win32 or DCPIL .NET A binary image containing a package header and the concatenation of all .dcu...