Delphi BX Manual de Início Rápido

Consulte online ou descarregue Manual de Início Rápido para Telefones Delphi BX. Delphi BX Quick start manual Manual do Utilizador

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 266
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes

Resumo do Conteúdo

Página 1 - Language Guide

Delphi Language GuideBorland Software Corporation100 Enterprise Way, Scotts Valley, CA 95066-3249http://www.borland.comBorland®Delphi™

Página 2

1-2Delphi Language GuideOther sources of informationThis manual generally assumes that you are working in the IDE and that you are building applicatio

Página 3 - Contents

5-38Delphi Language GuideType compatibility and identityType compatibilityEvery type is compatible with itself. Two distinct types are compatible if t

Página 4 - Procedures and functions 6-1

Data types, variables, and constants5-39Declaring types• T1 and T2 are compatible packed-string types.• T1 and T2 are compatible set types.• T1 and T2

Página 5

5-40Delphi Language GuideVariablesX and Y are of the same type; at runtime, there is no way to distinguish TValue from Real. This is usually of little

Página 6 - Program control 12-1

Data types, variables, and constants5-41VariablesConsecutive variable declarations do not have to repeat the reserved word var:varX, Y, Z: Double;I, J

Página 7 - Index I-1

5-42Delphi Language GuideDeclared constantsDynamic variablesYou can create dynamic variables by calling the GetMem or New procedure. Such variables ar

Página 8

Data types, variables, and constants5-43Declared constantsDeclared constants are either true constants or typed constants. These two kinds of constant

Página 9

5-44Delphi Language GuideDeclared constantsHere are some examples of constant declarations:constMin = 0;Max = 100;Center = (Max - Min) div 2;Beta = Ch

Página 10 - Other sources of information

Data types, variables, and constants5-45Resource stringsResource strings are stored as resources and linked into the executable or library so that the

Página 11 - Introduction

5-46Delphi Language Guidecreates an array called Maze whereMaze[0,0,0] = 0Maze[0,0,1] = 1Maze[0,1,0] = 2Maze[0,1,1] = 3Maze[1,0,0] = 4Maze[1,0,1] = 5M

Página 12

Data types, variables, and constants5-47Given these declarations, you can use the procedural constant MyFunction in a function call:I := MyFunction(5,

Página 13 - Basic language description

Introduction1-3Software registration and technical supportSoftware registration and technical supportBorland Software Corporation offers a range of su

Página 14

5-48Delphi Language Guide

Página 15 - Overview

Procedures and functions6-1Chapter6Chapter6Procedures and functionsProcedures and functions, referred to collectively as routines, are self-contained

Página 16 - Delphi source files

6-2Delphi Language GuideDeclaring procedures and functionsDeclaring procedures and functionsWhen you declare a procedure or function, you specify its

Página 17 - Example programs

Procedures and functions6-3Declaring procedures and functionsThis procedure call assigns the value “17” to MyString (which must be a string variable).

Página 18 - A more complicated example

6-4Delphi Language GuideDeclaring procedures and functionsdefines a constant function called WF that takes no parameters and always returns the intege

Página 19 - A native application

Procedures and functions6-5Declaring procedures and functionsIf the function exits without assigning a value to Result or the function name, then the

Página 20

6-6Delphi Language GuideDeclaring procedures and functionsThe directives near, far, and export refer to calling conventions in 16-bit Windows programm

Página 21

Procedures and functions6-7Declaring procedures and functionsWhen importing a C function that takes a variable number of parameters, use the varargs d

Página 22

6-8Delphi Language GuideDeclaring procedures and functionswhere the first stringConstant gives the name of the library file and the second stringConst

Página 23 - Programs and units

Procedures and functions6-9Declaring procedures and functionsYou can pass to an overloaded routine parameters that are not identical in type with thos

Página 24 - The block

1-4Delphi Language Guide

Página 25 - Unit structure and syntax

6-10Delphi Language GuideDeclaring procedures and functionsVariants can also be used as parameters in overloaded function declarations. Variant is con

Página 26 - The initialization section

Procedures and functions6-11Parametersin Unit1; if no routine in Unit1 matches the name and parameter list in the call, an error results.For informati

Página 27 - The finalization section

6-12Delphi Language GuideParametersthe = symbol and a default value. Parameter names must be valid identifiers. Any declaration can be preceded by var

Página 28 - The syntax of a uses clause

Procedures and functions6-13ParametersThese functions return the same result, but only the second one—DoubleByRef—can change the value of a variable p

Página 29

6-14Delphi Language GuideParametersas a var parameter to another routine. (But when you pass an object reference as a constant parameter, you can stil

Página 30 - Circular unit references

Procedures and functions6-15ParametersThe following example uses untyped parameters in a function called Equal that compares a specified number of byt

Página 31 - Syntactic elements

6-16Delphi Language GuideParametersArray parametersWhen you declare routines that take array parameters, you cannot include index type specifiers in t

Página 32 - Identifiers

Procedures and functions6-17ParametersNoteThe syntax of open array parameters resembles that of dynamic array types, but they do not mean the same thi

Página 33 - Reserved words

6-18Delphi Language GuideParametersVariant open array parametersVariant open array parameters allow you to pass an array of differently typed expressi

Página 34 - Numerals

Procedures and functions6-19ParametersDefault parametersYou can specify default parameter values in a procedure or function heading. Default values ar

Página 35 - Character strings

Basic language descriptionPartIPart IBasic language descriptionThe chapters in Part I present the essential language elements required for most progra

Página 36

6-20Delphi Language GuideDefault parameters and overloaded routinesIf you use default parameter values in an overloaded routine, avoid ambiguous param

Página 37 - Arithmetic operators

Procedures and functions6-21You can omit parentheses when passing all and only the default parameters to a routine. For example, given the procedurepr

Página 38 - Boolean operators

6-22Delphi Language Guide

Página 39 - String operators

Classes and objects7-1Chapter7Chapter7Classes and objectsA class, or class type, defines a structure consisting of fields, methods, and properties. In

Página 40 - Pointer operators

7-2Delphi Language GuideClass typesClass typesA class type must be declared and given a name before it can be instantiated. (You cannot define a class

Página 41 - Relational operators

Classes and objects7-3Class typesInheritance and scopeWhen you declare a class, you can specify its immediate ancestor. For example,type TSomeControl

Página 42 - The @ operator

7-4Delphi Language GuideClass typesObject typesAs an alternative to class types, you can declare object types using the syntaxtype objectTypeName = ob

Página 43 - Operator precedence rules

Classes and objects7-5Class typesYou can increase the visibility of a member in a descendant class by redeclaring it, but you cannot decrease its visi

Página 44 - Set constructors

7-6Delphi Language GuideClass typesA class cannot have published members unless it is compiled in the {$M+} state or descends from a class compiled in

Página 45 - Typecasts

Classes and objects7-7FieldsForward declarations allow mutually dependent classes. For example,typeTFigure = class; // forward declarationTDrawing = c

Página 47 - Declarations and statements

7-8Delphi Language GuideMethodsAlthough MyObject holds an instance of TDescendant, it is declared as TAncestor. The compiler therefore interprets MyOb

Página 48 - Statements

Classes and objects7-9MethodsMethod declarations can include special directives that are not used with other functions or procedures. Directives shoul

Página 49 - Simple statements

7-10Delphi Language GuideMethodsSelf is useful for a variety of reasons. For example, a member identifier declared in a class type might be redeclared

Página 50 - Goto statements

Classes and objects7-11MethodsVirtual and dynamic methodsTo make a method virtual or dynamic, include the virtual or dynamic directive in its declarat

Página 51 - Structured statements

7-12Delphi Language GuideMethodsOverriding versus hidingIf a method declaration specifies the same method identifier and parameter signature as an inh

Página 52 - With statements

Classes and objects7-13MethodsIf you overload a virtual method, use the reintroduce directive when you redeclare it in descendant classes. For example

Página 53 - If statements

7-14Delphi Language GuideMethodsparameters to the constructor. Finally, the constructor returns a reference to the newly allocated and initialized obj

Página 54

Classes and objects7-15MethodsDestructorsA destructor is a special method that destroys the object where it is called and deallocates its memory. The

Página 55 - Case statements

7-16Delphi Language GuideMethodsthe Messages unit. A message method must be a procedure that takes a single var parameter. For example, on Windows:typ

Página 56

Classes and objects7-17Propertiesfor the given ID, inherited calls the DefaultHandler method originally defined in TObject.The implementation of Defau

Página 57 - While statements

Overview2-1Chapter2Chapter2OverviewDelphi is a high-level, compiled, strongly typed language that supports structured and object-oriented design. Base

Página 58 - For statements

7-18Delphi Language GuidePropertiesProperties are defined by their access specifiers. Unlike fields, properties cannot be passed as var parameters, no

Página 59 - Blocks and scope

Classes and objects7-19PropertiesWhen a property is referenced in an expression, its value is read using the field or method listed in the read specif

Página 60

7-20Delphi Language GuidePropertiesArray propertiesArray properties are indexed properties. They can represent things like items in a list, child cont

Página 61 - Naming conflicts

Classes and objects7-21PropertiesThe definition of an array property can be followed by the default directive, in which case the array property become

Página 62

7-22Delphi Language GuidePropertiesGiven the declaration above, if Rectangle is of type TRectangle, thenRectangle.Right := Rectangle.Left + 100;corres

Página 63 - About types

Classes and objects7-23PropertiesProperty overrides and redeclarationsA property declaration that doesn’t specify a type is called a property override

Página 64

7-24Delphi Language GuideClass referencescan cast MyObject to TDescendant to access the descendant class’s properties and their access specifiers.type

Página 65 - Simple types

Classes and objects7-25Class referencesThis declaration says that to create a TCollection instance object, you must pass to the constructor the name o

Página 66 - Integer types

7-26Delphi Language GuideClass referencesThe is operatorThe is operator, which performs dynamic type checking, is used to verify the actual runtime cl

Página 67 - Character types

Classes and objects7-27ExceptionsThe defining declaration of a class method must also begin with class. For example,class procedure TFigure.GetInfo(va

Página 68 - Enumerated types

2-2Delphi Language GuideProgram organizationDelphi source filesThe compiler expects to find Delphi source code in files of three kinds:• unit source f

Página 69

7-28Delphi Language GuideExceptionsConditional statements are often the best way to test for errors. For example, suppose you want to make sure that a

Página 70 - Subrange types

Classes and objects7-29ExceptionsRaising and handling exceptionsTo raise an exception object, use an instance of the exception class with a raise stat

Página 71

7-30Delphi Language GuideExceptionsTry...except statementsExceptions are handled within try...except statements. For example,tryX := Y/Z;excepton EZer

Página 72

Classes and objects7-31ExceptionsWhen an exception is handled, the stack is traced back to the procedure or function containing the try...except state

Página 73 - String types

7-32Delphi Language GuideExceptionsAn exception block that contains no exception handlers, but instead consists only of a list of statements, handles

Página 74 - Short strings

Classes and objects7-33Nested exceptionsCode executed in an exception handler can itself raise and handle exceptions. As long as these exceptions are

Página 75 - WideString

7-34Delphi Language Guidewhere each statementList is a sequence of statements delimited by semicolons. The try...finally statement executes the statem

Página 76

Standard routines and I/O8-1Chapter8Chapter8Standard routines and I/OThis chapter discusses text and file I/O and summarizes standard library routines

Página 77

8-2Delphi Language GuideFile input and outputA file variable is any variable whose type is a file type. There are three classes of file: typed, text,

Página 78

Standard routines and I/O8-3File input and outputWhen a program completes processing a file, the file must be closed using the standard procedure Clos

Página 79 - Structured types

Overview2-3Example programsVarious tools in the IDE store data in files of other types. Desktop settings (.dsk or .desk) files contain information abo

Página 80

8-4Delphi Language GuideText file device driversSome of the standard I/O routines that work on text files don’t need to have a file variable explicitl

Página 81 - Static arrays

Standard routines and I/O8-5Text file device driversTo associate the device-interface functions with a specific file, you must write a customized Assi

Página 82 - Dynamic arrays

8-6Delphi Language GuideHandling null-terminated stringsThe InOut functionThe InOut function is called by the Read, Readln, Write, Writeln, Eof, Eoln,

Página 83

Standard routines and I/O8-7Handling null-terminated stringsStandard string-handling functions have multibyte-enabled counterparts that also implement

Página 84 - Array types and assignments

8-8Delphi Language GuideOther standard routinesOther standard routinesThe table below lists frequently used procedures and functions found in Borland

Página 85

Standard routines and I/O8-9Other standard routinesFormatFloat Formats a floating point value.FreeMem Releases allocated memory.GetMem Allocates dynam

Página 86 - Variant parts in records

8-10Delphi Language GuideOther standard routinesFor information on format strings, see “Format strings” in the online Help.StrToCurr Converts a string

Página 87

Special topicsPartIIPart IISpecial topicsThe chapters in Part II cover specialized language features and advanced topics. These chapters include:• Cha

Página 89 - Pointers and pointer types

Libraries and packages9-1Chapter9Chapter9Libraries and packagesA dynamically loadable library is a dynamic-link library (DLL) on Windows or a shared o

Página 90

2-4Delphi Language GuideExample programsThe first line declares a program called Greeting. The {$APPTYPE CONSOLE} directive tells the compiler that th

Página 91

9-2Delphi Language GuideCalling dynamically loadable librariesStatic loadingThe simplest way to import a procedure or function is to declare it using

Página 92

Libraries and packages9-3Calling dynamically loadable librariesbeginHandle := LoadLibrary('libraryname');if Handle <> 0 thenbegin@GetT

Página 93

9-4Delphi Language GuideWriting dynamically loadable librariesIn this case, when importing routines, the shared object is not loaded until the code co

Página 94

Libraries and packages9-5Writing dynamically loadable librariesLibraries can be built from multiple units. In this case, the library source file is fr

Página 95

9-6Delphi Language GuideWriting dynamically loadable librariesThe exports clauseA routine is exported when it is listed in an exports clause, which ha

Página 96 - Variant type conversions

Libraries and packages9-7Writing dynamically loadable librariesLibrary initialization codeThe statements in a library’s block constitute the library’s

Página 97 - Variants in expressions

9-8Delphi Language GuideWriting dynamically loadable librariesGlobal variables in a libraryGlobal variables declared in a shared library cannot be imp

Página 98 - OleVariant

Libraries and packages9-9Writing dynamically loadable librariesExceptions and runtime errors in librariesWhen an exception is raised but not handled i

Página 99 - Type identity

9-10Delphi Language GuidePackagesPackagesA package is a specially compiled library used by applications, the IDE, or both. Packages allow you to rearr

Página 100 - Assignment-compatibility

Libraries and packages9-11Packageswhere packageName is any valid identifier. The requiresClause and containsClause are both optional. For example, the

Página 101 - Declaring types

Overview2-5Example programsdefined in Unit1. Here’s the source code for Unit1, which must be saved in a file called Unit1.pas:unit Unit1;interfaceproc

Página 102 - Variables

9-12Delphi Language GuidePackagesThe requires clauseThe requires clause lists other, external packages that are used by the current package. It functi

Página 103 - Absolute addresses

Libraries and packages9-13Compiling packagesPackages are ordinarily compiled from the IDE using .dpk files generated by the Package editor. You can al

Página 104 - Declared constants

9-14Delphi Language GuideIncluding {$DENYPACKAGEUNIT ON} in source code prevents the unit file from being packaged. Including {$G–} or {$IMPORTEDDATA

Página 105 - True constants

Object interfaces10-1Chapter10Chapter10Object interfacesAn object interface—or simply interface—defines methods that can be implemented by a class. In

Página 106 - Constant expressions

10-2Delphi Language GuideInterface types• All members of an interface are public. Visibility specifiers and storage specifiers are not allowed. (But a

Página 107 - Typed constants

Object interfaces10-3Interface typesInterface identificationAn interface declaration can specify a globally unique identifier (GUID), represented by a

Página 108 - Procedural constants

10-4Delphi Language GuideImplementing interfacesInterface propertiesProperties declared in an interface are accessible only through expressions of the

Página 109 - Pointer constants

Object interfaces10-5Implementing interfacesdeclares a class called TMemoryManager that implements the IMalloc and IErrorInfo interfaces. When a class

Página 110 - Delphi Language Guide

10-6Delphi Language GuideImplementing interfacesFor example, the class declarationtypeTMemoryManager = class(TInterfacedObject, IMalloc, IErrorInfo)fu

Página 111 - Procedures and functions

Object interfaces10-7Implementing interfacesImplementing interfaces by delegationThe implements directive allows you to delegate implementation of an

Página 112 - Procedure declarations

Refer to the DEPLOY document located in the root directory of your product for a complete list of files that you can distribute in accordance with the

Página 113 - Function declarations

2-6Delphi Language GuideExample programsbegin{ calls to Application }Application.Initialize;Application.CreateForm(TForm1, Form1);Application.CreateFo

Página 114

10-8Delphi Language GuideImplementing interfacesDelegating to a class-type propertyIf the delegate property is of a class type, that class and its anc

Página 115 - Calling conventions

Object interfaces10-9Interface referencesInterface referencesIf you declare a variable of an interface type, the variable can reference instances of a

Página 116 - External declarations

10-10Delphi Language GuideInterface referencesInterface references are typically managed through reference-counting, which depends on the _AddRef and

Página 117 - Linking to object files

Object interfaces10-11Automation objects (Windows only)An interface query returns nil if object is nil. Otherwise, it passes the GUID of interface to

Página 118

10-12Delphi Language GuideAutomation objects (Windows only)Dispatch interface propertiesProperties of a dispatch interface do not include access speci

Página 119

Object interfaces10-13Automation objects (Windows only)Some Automation servers allow you to omit parameters from a method call, accepting their defaul

Página 120

10-14Delphi Language Guide

Página 121 - Parameters

Memory management11-1Chapter11Chapter11Memory managementThis chapter explains how programs use memory and describes the internal formats of Delphi dat

Página 122 - Parameter semantics

11-2Delphi Language GuideThe memory manager (Windows only)The memory manager maintains two status variables, AllocMemCount and AllocMemSize, which con

Página 123 - Constant parameters

Memory management11-3Internal data formatsInternal data formatsThe following sections describe the internal formats of Delphi data types.Integer types

Página 124 - Untyped parameters

Overview2-7Example programsUnit1 creates a class named TForm1 (derived from TForm) and an instance of this class, Form1. TForm1 includes a button—Butt

Página 125 - String parameters

11-4Delphi Language GuideInternal data formatsReal typesThe real types store the binary representation of a sign (+ or –), an exponent, and a signific

Página 126 - Array parameters

Memory management11-5Internal data formatsThe Double typeAn 8-byte (64-bit) Double number is divided into three fields:The value v of the number is gi

Página 127

11-6Delphi Language GuideInternal data formatsLong string typesA long string variable occupies four bytes of memory which contain a pointer to a dynam

Página 128 - Variant open array parameters

Memory management11-7Internal data formatsThe NULL character at the end of a wide string memory block is automatically maintained by the compiler and

Página 129 - Default parameters

11-8Delphi Language GuideInternal data formatsRecord typesWhen a record type is declared in the {$A+} state (the default), and when the declaration do

Página 130

Memory management11-9Internal data formatsFile typesFile types are represented as records. Typed files and untyped files occupy 332 bytes, which are l

Página 131 - Open array constructors

11-10Delphi Language GuideInternal data formatswhere fmClosed indicates that the file is closed, fmInput and fmOutput indicate a text file that has be

Página 132

Memory management11-11Internal data formatscorresponding virtual method’s entry point. This layout is compatible with a C++ v-table and with COM. At n

Página 133 - Classes and objects

11-12Delphi Language GuideInternal data formatsVariant typesA variant is stored as a 16-byte record that contains a type code and a value (or a refere

Página 134 - Class types

Program control12-1Chapter12Chapter12Program controlThis chapter explains how parameters and function results are stored and transferred. The final se

Página 135 - Inheritance and scope

2-8Delphi Language GuideWhen the Greeting program starts, Form1 is displayed and Form2 is invisible. (By default, only the first form created in the p

Página 136 - Visibility of class members

12-2Delphi Language GuideParameters and function results• A long-string or dynamic-array parameter is passed as a 32-bit pointer to the dynamic memory

Página 137 - Published members

Program control12-3Parameters and function resultsRegister saving conventionsProcedures and functions must preserve the EBX, ESI, EDI, and EBP registe

Página 138 - Automated members

12-4Delphi Language GuideParameters and function resultsMethod callsMethods use the same calling conventions as ordinary procedures and functions, exc

Página 139

Program control12-5Exit proceduresExit proceduresExit procedures ensure that specific actions—such as updating and closing files—are carried out befor

Página 140

12-6Delphi Language GuideAn exit procedure can learn the cause of termination by examining the ExitCode integer variable and the ErrorAddr pointer var

Página 141 - Inherited

Inline assembly code13-1Chapter13Chapter13Inline assembly codeThe built-in assembler allows you to write assembly code within Delphi programs. It has

Página 142 - Method binding

13-2Delphi Language GuideAssembler statement syntaxRegister useIn general, the rules of register use in an asm statement are the same as those of an e

Página 143 - Virtual and dynamic methods

Inline assembly code13-3Assembler statement syntaxInstruction opcodesThe built-in assembler supports all of the Intel-documented opcodes for general a

Página 144 - Overloading methods

13-4Delphi Language GuideAssembler statement syntaxAssembly directivesThe built-in assembler supports three assembly define directives: DB (define byt

Página 145 - Constructors

Inline assembly code13-5Assembler statement syntaxWhen an identifier precedes a DB, DW, or DD directive, it causes the declaration of a byte-, word-,

Página 146

Programs and units3-1Chapter3Chapter3Programs and unitsA program is constructed from source-code modules called units. Each unit is stored in its own

Página 147 - Message methods

13-6Delphi Language GuideAssembler statement syntaxDMTINDEX retrieves the dynamic method table index of the passed dynamic method. This directive also

Página 148 - Implementing message methods

Inline assembly code13-7Assembler statement syntaxprocedure CallVirtualMethod(e: TExample);asm // Instance pointer needs to be in EAX MOV EAX, e

Página 149 - Properties

13-8Delphi Language GuideExpressionsReserved words always take precedence over user-defined identifiers. For example,varCh: Char;ƒasmMOV CH, 1end;load

Página 150 - Property access

Inline assembly code13-9Expressionsthe built-in assembler cannot compute the value of X + Y at compile time. In this case, to move the sum of X and Y

Página 151

13-10Delphi Language GuideExpressionsString constantsString constants must be enclosed in single or double quotation marks. Two consecutive quotation

Página 152 - Array properties

Inline assembly code13-11ExpressionsRegistersThe following reserved symbols denote CPU registers in the inline assembler:When an operand consists sole

Página 153 - Index specifiers

13-12Delphi Language GuideExpressionsThe following symbols cannot be used in asm statements:• Standard procedures and functions (for example, WriteLn

Página 154 - Storage specifiers

Inline assembly code13-13ExpressionsIdentifiers can be qualified within asm statements. For example, given the declarationstypeTPoint = recordX, Y: In

Página 155

13-14Delphi Language GuideExpressionsImmediate values and memory references cause different code to be generated when used as operands. For example,co

Página 156 - Class references

Inline assembly code13-15ExpressionsExpression typesEvery built-in assembler expression has a type—or, more correctly, a size, because the assembler r

Página 157 - Class operators

3-2Delphi Language GuideProgram structure and syntaxThe following example shows the project file for a program called Editor.1 program Editor;23 uses4

Página 158 - Class methods

13-16Delphi Language GuideThe following table summarizes the predefined type symbols that the built-in assembler provides in addition to any currently

Página 159 - Exceptions

Inline assembly code13-17. Structure member selector. The result is the sum of the expression before the period and the expression after the period, w

Página 160 - Declaring exception types

13-18Delphi Language GuideAssembly procedures and functionsYou can write complete procedures and functions using inline assembly language code, withou

Página 161

Inline assembly code13-19Assembly language functions return their results as follows.• Ordinal values are returned in AL (8-bit values), AX (16-bit va

Página 162 - Try...except statements

13-20Delphi Language Guide

Página 163

Delphi grammarA-1AppendixAAppendix ADelphi grammarGoal -> (Program | Package | Library | Unit)Program -> [PROGRAM Ident ['(' IdentList

Página 164 - Re-raising exceptions

A-2Delphi Language GuideImplementationSection -> IMPLEMENTATION[UsesClause][DeclSection]...[ExportsStmt]...Block -> [DeclSection][ExportsStmt]..

Página 165 - Try...finally statements

Delphi grammarA-3RealType -> REAL48-> REAL-> SINGLE-> DOUBLE-> EXTENDED-> CURRENCY-> COMPOrdinalType -> (SubrangeType | Enumer

Página 166

A-4Delphi Language GuideVarSection -> VAR (VarDecl ';')...VarDecl On Windows -> IdentList ':' Type [(ABSOLUTE (Ident | Const

Página 167 - Standard routines and I/O

Delphi grammarA-5StructStmt -> CompoundStmt-> ConditionalStmt-> LoopStmt-> WithStmt-> TryExceptStmt-> TryFinallyStmt-> RaiseStmt-

Página 168 - Procedure or

Programs and units3-3Unit structure and syntaxstatements are simply method calls to the project’s Application object (most projects have an Applicatio

Página 169 - Text files

A-6Delphi Language GuideFunctionHeading -> FUNCTION Ident [FormalParameters] ':' (SimpleType | STRING)ProcedureHeading -> PROCEDURE Id

Página 170 - Text file device drivers

Delphi grammarA-7ClassFieldList -> (ClassVisibility ObjFieldList) ';'...ClassMethodList -> (ClassVisibility MethodList) ';'.

Página 171 - Device functions

A-8Delphi Language Guide

Página 172 - The Close function

IndexI-1Symbols- 4-4, 4-7, 4-10, 4-11" 13-10#4-5$4-4, 4-6(*, *) 4-6(, ) 4-2, 4-13, 4-15, 5-6, 5-45, 6-2, 6-3, 6-11, 7-2, 10-1* 4-2, 4-7, 4-11+ 4-

Página 173 - Wide-character strings

I-2Delphi Language GuideB$B directive 4-9base types 5-8, 5-18, 5-19, 5-20begin (reserved word) 3-2, 4-21, 6-2, 6-3binary operators 4-7bindingfields 7-

Página 174 - Other standard routines

IndexI-3CmdLine variable 9-8COM 10-4interfaces 10-2, 10-11 to 10-13out parameters 6-14variants and 5-33, 5-35, 11-12COM error handling 6-5comments 4-1

Página 175

I-4Delphi Language Guidedefault properties 7-21interfaces 10-2default property (COM object) 5-35default specifier 7-6, 7-17, 7-22DefaultHandler method

Página 176

IndexI-5EE (in numerals) 4-4EAssertionFailed 7-28else (reserved word) 4-24, 4-26, 7-30empty set 5-18end (reserved word) 3-2, 4-21, 4-25, 5-23, 5-24, 6

Página 177 - Special topics

I-6Delphi Language GuideG-$G- compiler switch 9-14$G directive 9-13generic types 5-1GetHeapStatus function 11-2GetMem procedure 5-28, 5-42, 9-9, 11-1,

Página 178

IndexI-7interface declarations 3-4default paramters 6-20interface section 3-3, 3-4, 3-7forward declarations and 6-6methods 7-8scope 4-31uses clause 3-

Página 179 - Libraries and packages

3-4Delphi Language GuideUnit structure and syntaxUnit names must be unique within a project. Even if their unit files are in different directories, tw

Página 180 - Dynamic loading

I-8Delphi Language Guidedual-interface 6-5dynamic 7-10, 7-11implementation 7-8overloading 7-12overriding 7-11, 7-12, 10-6pointers 4-13, 5-31publishing

Página 181

IndexI-9P$P directive 6-15package files 2-2, 2-3, 9-10, 9-13packages 9-10 to 9-14compiler directives 9-13compiler switches 9-14compiling 9-13declaring

Página 182

I-10Delphi Language Guideprogram, control 6-20program (reserved word) 3-2program control ?? to 12-6programs 2-1 to 2-5, 3-1 to 3-8examples 2-3 to 2-5s

Página 183

IndexI-11resource strings 5-45resourcestring (reserved word) 5-45Result variable 6-3, 6-4RET instruction 13-3return type (functions) 6-3, 6-4return va

Página 184 - The exports clause

I-12Delphi Language GuideStringToWideChar function 8-7strong typing 5-1structured statements 4-21structured types 5-17files and 5-26records and 5-25va

Página 185 - Library initialization code

IndexI-13set 5-18, 11-7simple 5-3string 5-11 to 5-17, 11-5, 11-6structured 5-17subrange 5-8type identity 5-37user-defined 5-1variant 5-33 to 5-37typog

Página 186 - Global variables in a library

I-14Delphi Language GuideW$WARNINGS directive 4-18$WEAKPACKAGEUNIT directive 9-13while statements 4-21, 4-27wide characters and strings 5-13memory man

Página 187

Programs and units3-5Unit references and the uses clauseSo, for example, if you have defined data structures that need to be initialized, you can do t

Página 188 - Packages

3-6Delphi Language GuideUnit references and the uses clauseIf such an explicit reference appears in the project file, other source files can refer to

Página 189 - Naming packages

Programs and units3-7Unit references and the uses clauseIn the uses clause of a unit, you cannot use in to tell the compiler where to find a source fi

Página 190 - The contains clause

iiiChapter 1Introduction 1-1What’s in this manual? . . . . . . . . . . . . . . 1-1Using Delphi . . . . . . . . . . . . .

Página 191 - Compiling packages

3-8Delphi Language GuideUnit references and the uses clauseCircular unit referencesWhen units reference each other directly or indirectly, the units a

Página 192 - Switch Purpose

Syntactic elements4-1Chapter4Chapter4Syntactic elementsThe Delphi Language uses the ASCII character set, including the letters A through Z and a throu

Página 193 - Object interfaces

4-2Delphi Language GuideFundamental syntactic elementsSpecial symbolsSpecial symbols are non-alphanumeric characters, or pairs of such characters, tha

Página 194 - IInterface and inheritance

Syntactic elements4-3Fundamental syntactic elementsQualified identifiersWhen you use an identifier that has been declared in more than one place, it i

Página 195 - Interface identification

4-4Delphi Language GuideFundamental syntactic elementsDirectivesDirectives are words that are sensitive in specific locations within source code. Dire

Página 196 - Implementing interfaces

Syntactic elements4-5Fundamental syntactic elementsLabelsA label is a standard Delphi language identifier with the exception that, unlike other identi

Página 197 - Method resolution clauses

4-6Delphi Language GuideComments and compiler directivesComments and compiler directivesComments are ignored by the compiler, except when they functio

Página 198

Syntactic elements4-7ExpressionsThe operators @, not, and ^ are unary (taking one operand). All other operators are binary (taking two operands), exce

Página 199

4-8Delphi Language GuideExpressions•The mod operator returns the remainder obtained by dividing its operands. In other words, x mod y = x – (x div y)

Página 200

Syntactic elements4-9ExpressionsUse the $B compiler directive to control evaluation mode. The default state is {$B–}, which enables short-circuit eval

Página 201 - Interface references

ivCase statements . . . . . . . . . . . . . . .4-25Control loops . . . . . . . . . . . . . . . . 4-27Repeat statements.

Página 202 - Interface typecasts

4-10Delphi Language GuideExpressionsThe following rules apply to string concatenation.•The operands for + can be strings, packed strings (packed array

Página 203

Syntactic elements4-11ExpressionsSet operatorsThe following operators take sets as operands.The following rules apply to +, –, and *.•An ordinal O is

Página 204 - Dispatch interface properties

4-12Delphi Language GuideExpressionsFor most simple types, comparison is straightforward. For example, I = J is True just in case I and J have the sam

Página 205

Syntactic elements4-13Expressions• When @ is applied to a method defined in a class, the method identifier must be qualified with the class name. For

Página 206

4-14Delphi Language GuideExpressionsWithout parentheses, however, the compiler follows operator precedence rules and reads it as(X = (Y or X)) = Zwhic

Página 207 - Memory management

Syntactic elements4-15ExpressionsExamples of set constructors:[red, green, MyColor][1, 5, 10..K mod 12, 23]['A'..'Z', 'a&apos

Página 208

4-16Delphi Language GuideExpressionsVariable typecastsYou can cast any variable to any type, provided their sizes are the same and you do not mix inte

Página 209 - Internal data formats

Syntactic elements4-17Declarations and statementsIn this example, TByteRec is used to access the low- and high-order bytes of a word, and TWordRec to

Página 210 - Real types

4-18Delphi Language GuideDeclarations and statementsHinting DirectivesThe “hint” directives platform, deprecated, and library may be appended to any d

Página 211 - Short string types

Syntactic elements4-19Declarations and statementsSimple statementsA simple statement doesn’t contain any other statements. Simple statements include a

Página 212 - Wide string types (Windows)

vString parameters. . . . . . . . . . . . . . . . 6-15Array parameters. . . . . . . . . . . . . . . .6-16Open array para

Página 213 - Dynamic array types

4-20Delphi Language GuideDeclarations and statementsWhen you use a function call in this way, its return value is discarded.For more information about

Página 214 - Record types

Syntactic elements4-21Declarations and statementsƒ {code to execute if no answer is found }Exit;FoundAnAnswer:ƒ { code to execute when an answer is fo

Página 215 - File types

4-22Delphi Language GuideDeclarations and statementsCompound statements are essential in contexts where Delphi syntax requires a single statement. In

Página 216 - Procedural types

Syntactic elements4-23Declarations and statementsThis is equivalent toif OrderDate.Month = 12 thenbeginOrderDate.Month := 1;OrderDate.Year := OrderDat

Página 217 - Class reference types

4-24Delphi Language GuideDeclarations and statementsThe syntax of an if...then...else statement isif expression then statement1 else statement2where e

Página 218 - Variant types

Syntactic elements4-25Declarations and statementsis equivalent toif ... { expression1 } thenbeginif ... { expression2 } then... { statement1 }else...

Página 219 - Program control

4-26Delphi Language GuideDeclarations and statementsEach value represented by a caseList must be unique in the case statement; subranges and lists can

Página 220

Syntactic elements4-27Declarations and statementsControl loopsLoops allow you to execute a sequence of statements repeatedly, using a control conditio

Página 221 - Function results

4-28Delphi Language GuideDeclarations and statementsExamples of while statements includewhile Data[I] <> X do I := I + 1;while I > 0 dobegini

Página 222 - Method calls

Syntactic elements4-29Blocks and scopeFor purposes of controlling execution of the loop, the expressions initialValue and finalValue are evaluated onl

Página 223 - Exit procedures

viExceptions and runtime errors in libraries . . . . . . . . . . . . . . . 9-9Shared-memory manager (Windows only) . . . . . .

Página 224

4-30Delphi Language GuideBlocksA block consists of a series of declarations followed by a compound statement. All declarations must occur together at

Página 225 - Inline assembly code

Syntactic elements4-31The rules that determine identifier scope are summarized below.Naming conflictsWhen one block encloses another, the former is ca

Página 226 - Assembler statement syntax

4-32Delphi Language GuideThe System and SysInit units are used automatically by every program or unit. The declarations in System, along with the pred

Página 227 - Instruction opcodes

Data types, variables, and constants5-1Chapter5Chapter5Data types, variables, and constantsA type is essentially a name for a kind of data. When you d

Página 228 - Assembly directives

5-2Delphi Language GuideAbout typesportability. However, changes in storage format from one implementation of a generic type to the next could cause c

Página 229

Data types, variables, and constants5-3Simple typesSimple typesSimple types, which include ordinal types and real types, define ordered sets of values

Página 230

5-4Delphi Language GuideSimple typesInteger typesAn integer type represents a subset of the whole numbers. The generic integer types are Integer and C

Página 231 - Operands

Data types, variables, and constants5-5Simple typesWhen you increment the last value or decrement the first value of an integer type, the result wraps

Página 232 - Expressions

5-6Delphi Language GuideSimple typesFor more information about Unicode characters, see “About extended character sets” on page 5-13 and “Working with

Página 233 - Expression elements

Data types, variables, and constants5-7Simple typesdefines an enumerated type called Suit whose possible values are Club, Diamond, Heart, and Spade, w

Página 234 - String constants

viiChapter 13Inline assembly code 13-1The asm statement . . . . . . . . . . . . . . . . .13-1Register use . . . . . . . . . .

Página 235 - Registers

5-8Delphi Language GuideSimple typesEnumerated types with explicitly assigned ordinalityBy default, the ordinalities of enumerated values start from 0

Página 236 - Symbol Value Class Type

Data types, variables, and constants5-9Simple typesYou can use numeric constants and characters (string constants of length 1) to define subrange type

Página 237 - Expression classes

5-10Delphi Language GuideSimple typesReal typesA real type defines a set of numbers that can be represented with floating-point notation. The table be

Página 238

Data types, variables, and constants5-11String typesString typesA string represents a sequence of characters. Delphi supports the following predefined

Página 239 - Expression types

5-12Delphi Language GuideString typesBe careful indexing strings in this way, since overwriting the end of a string can cause access violations. Also,

Página 240 - Expression operators

Data types, variables, and constants5-13String typesLong stringsAnsiString, also called a long string, represents a dynamically allocated string whose

Página 241 - Operator Description

5-14Delphi Language GuideString typessystem supports Unicode (UCS-2). The Linux operating system supports UCS-4, a superset of UCS-2. Borland’s RAD pr

Página 242

Data types, variables, and constants5-15String typespoints P to an area of memory that contains a null-terminated copy of “Hello world!” This is equiv

Página 243

5-16Delphi Language GuideString typesThe StrUpper function illustrates the use of pointer indexing to iterate through a null-terminated string:functio

Página 244

Data types, variables, and constants5-17Structured types•PChar(S) always returns a pointer to a memory block; if S is empty, a pointer to #0 is return

Página 245 - Delphi grammar

viii4.1 Equivalent symbols . . . . . . . . . . . . . 4-24.2 Reserved words . . . . . . . . . . . . . . . 4-34.3 Directi

Página 246

5-18Delphi Language GuideStructured typesSetsA set is a collection of values of the same ordinal type. The values have no inherent order, nor is it me

Página 247

Data types, variables, and constants5-19Structured typesArraysAn array represents an indexed collection of elements of the same type (called the base

Página 248

5-20Delphi Language GuideStructured typesDynamic arraysDynamic arrays do not have a fixed size or length. Instead, memory for a dynamic array is reall

Página 249

Data types, variables, and constants5-21Structured typesIn contrast, to make an independent copy of a dynamic array, you must use the global Copy func

Página 250

5-22Delphi Language GuideStructured typesMultidimensional dynamic arraysTo declare multidimensional dynamic arrays, use iterated array of ... construc

Página 251

Data types, variables, and constants5-23Structured typesTo make the assignment work, declare the variables asvar Int1, Int2: array[1..10] of Integer;o

Página 252

5-24Delphi Language GuideStructured typesOr use a with statement:with Record1 dobeginYear := 1904;Month := Jun;Day := 16;end;You can now copy the valu

Página 253

Data types, variables, and constants5-25Structured types•Each constantList is a constant denoting a value of type ordinalType, or a comma-delimited li

Página 254

5-26Delphi Language GuideStructured typestypeTShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);TFigure = recordcase TShapeList ofRectangle: (

Página 255

Data types, variables, and constants5-27Pointers and pointer typesYou can also use the file of ... construction directly in a variable declaration. Fo

Página 256

Introduction1-1Chapter1Chapter1IntroductionThis manual describes the Delphi programming language as it is used in Borland development tools.What’s in

Página 257

5-28Delphi Language GuidePointers and pointer typesThe symbol ^ has two purposes, both of which are illustrated in our example. When it appears before

Página 258

Data types, variables, and constants5-29Pointers and pointer typesPointer typesYou can declare a pointer to any type, using the syntaxtype pointerType

Página 259

5-30Delphi Language GuideProcedural typesProcedural typesProcedural types allow you to treat procedures and functions as values that can be assigned t

Página 260

Data types, variables, and constants5-31Procedural typesThe previous variables are all procedure pointers—that is, pointers to the address of a proced

Página 261

5-32Delphi Language GuideProcedural typesProcedural types in statements and expressionsWhen a procedural variable is on the left side of an assignment

Página 262

Data types, variables, and constants5-33Variant typesThe @ operator can also be used to assign an untyped pointer value to a procedural variable. For

Página 263

5-34Delphi Language GuideVariant typesThe standard function VarType returns a variant’s type code. The varTypeMask constant is a bit mask used to extr

Página 264

Data types, variables, and constants5-35Variant typesOut-of-range assignments often result in the target variable getting the highest value in its ran

Página 265

5-36Delphi Language GuideVariant typesIn this example, the Else part of the If statement will be executed. This behavior can be changed by setting the

Página 266

Data types, variables, and constants5-37Type compatibility and identityWhen you assign a Variant that contains custom data (such as a Delphi string, o

Comentários a estes Manuais

Sem comentários