Delphi, Lazarus reserved words, keywords.

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Delphi,Lazarus reserved words, keywords.


From oranges, in case of blogs and other places


Keyword: variable identifier can be used,

Keywords: specific meaning, can not be re defined,

Modifier: similar to the reserved word function, that is to say, reuse ,

Data type: the data type similar to the reserved word, generally do not redefine,

A prompt character: this information is used to prompt the user to platform depEndent purposes at compile time, do not change.


But the reserved word or try not to re definition, as the following code

procedure TForm1.FormCreate(SEnder: TObject);

var true:string;

Begin


End;

Can correct implementation.

The same identifier is also similar to the reserved word, the following procedure may also be performed:

type  Integer= Char;

var  I: Integer;

Begin  I:= 'A';  ShowMessage(I);End;

But the following program will report an error.

type string = Integer;

So whether reserved words, identifiers, keywords, modifier are best not re definition,



Turbo pascal The reserved word


and

array

asm

begin

break

case

const

constructor

continue

destructor

div

do

downto

Else

End

false

file

for

function

goto

if

implementation

in

inline

interface

label

mod

nil

not

object

of

on

operator

or

packed

procedure

program

record

repeat

set

shl

shr

string

then

to

true

type

unit

until

uses

var

while

with

xor

   

Object The Pascal reserved word

as

class

dispose

except

exit

exports

finalization

finally

inherited

initialization

is

library

new

on

out

property

raise

self

threadvar

try


The Delphi keyword

And

Array

As

Begin

Case

Class

Const

Constructor

Destructor

Div

Do

DownTo

Else

End

Except

File

Finally

For

Function

Goto

If

Implementation

In

Inherited

Interface

Is

Mod

Not

Object

Of

On

Or

Packed

Procedure

Program

Property

Raise

Record

Repeat

Set

Shl

Shr

Then

ThreadVar

To

Try

Type

Unit

Until

Uses

Var

While

With

     


Delphi reserved words and keywords

Absolute

Abstract

And

Array

As

Asm

Assembler

Automated

Begin

Case

Cdecl

Class

Const

Constructor

Contains

Default

Destructor

Dispid

Dispinterface

Div

Do

Downto

Dynamic

Else

End

Except

Export

Exports

External

Far

File

Finalization

Finally

For

Forward

Function

Goto

If

Implementation

Implements

In

Index

Inherited

Initialization

Inline

Interface

Is

Label

Library

Message

Mod

Name

Near

Nil

Nodefault

Not

Object

Of

On

Or

Out

Overload

Override

Package

Packed

Pascal

Private

Procedure

Program

Property

Protected

Public

Published

Raise

Read

Readonly

Record

Register

Reintroduce

Repeat

Requires

Resourcestring

Safecall

Set

Shl

Shr

Stdcall

Stored

String

Then

Threadvar

To

Try

Unit

Until

Uses

Var

Varargs

Virtual

While

With

Write

Writeonly

Xor


Freepascal Modifier supported include turbopascal and object  the reserved word Pascal (in which the red part is different and Delphi)

absolute

abstract

alias

assembler

cdecl

cppdecl

default

export

external

forward

index

local

name

nostackframe

oldfpccall

override

pascal

Private

protected

Public

Published

read

register

reintroduce

safecall

softfloat

stdcall

virtual

write

     


Modifier Freepascal is no longer supported

=========================================================

far

near

   


ISO 7185 The standard key

And

Downto

If

Or

Then

Array

Else

In

Packed

To

Begin

End

Label

Procedure

Type

Case

File

Mod

Program

Until

Const

For

Nil

Record

Var

Div

Function

Not

Repeat

While

Do

Goto

Of

Set

With

ISO 10206 ExtEnded Pascal keyword

And_then

Import

Module

Otherwise

Qualified

Bindable

Implementation

Only

Pow

Restricted

Export

Interface

Or_Else

Protected

Value

Turbo Pascal Keyword

Absolute

Destructor

Inline

Shl

Uses

Asm

Implementation

Interface

Shr

Virtual

Constructor

Inherited

Object

Unit

Xor

Delphi To increase keyword

as

exports

initialization

on

threadvar

class

finalization

is

property

try

except

finally

library

raise

 

Free Pascal Keyword

dispose

exit

false

new

true

Object Pascal Keyword

Abstract

Constructor

Inherited

Object

View

Class

Destructor

Is

Property

Virtual

GNU Keyword

All

Asm

Inline

   

Pascal Keyword expansion of scientific computing

Module

Operator

The data type identifier

Integer

Shortint

SmallInt

Longint

Longword

Int64

Byte

Word

Cardinal

QWord

Boolean

ByteBool

WordBool

LongBool

Char

Real

Single

Double

ExtEnded

Comp

Currency

Char

Strings

Shortstrings

Ansistrings

UnicodeStrings

WideStrings

Constantstrings

PChar

Array

Record

VariantInteger

Shortint

SmallInt

Longint

Longword

Int64

Byte

Word

Cardinal

QWord

Boolean

ByteBool

WordBool

LongBool

Char

Real

Single

Double

ExtEnded

Comp

Currency

Char

Strings

Shortstrings

Ansistrings

UnicodeStrings

WideStrings

Constantstrings

PChar

Array

Record

Variant

 

In addition, the above types of variables are windows, FPC, some types of variable LCL predefined, they are equivalent to the reserved word function, also do not change.


Lazarus,FreePascal's proprietary prompt character

deprecated 

experimental 

platform 

unimplemented 



Below are all reserved words, explain in detail the key

======================================================

absolute 

//It allows you to create a new variable,   and the starting address of the variable with another variable.

var

  Str:  string[32];

  StrLen: Byte absolute Str;


//This statement specifies a variable StrLen address and the same Str.

//Because a string of zeroth location to save the length of the string, the string length value   StrLen.

begin

  Str := 'abc';

  Edit1.Text := IntToStr(StrLen);

End;



abstract//The   method, which allows you to create abstract; including the abstract class is called an abstract class.

//The Abstract keyword must be used, at the same time with the Virtual or Dynamic keyword   because the abstract method must be covered.

//Abstract class cannot be instantiated,   abstract method cannot have a method body.

type

  TDemo  =  class

Private

protected

Procedure  X;   virtual; abstract;

Public

constructor Create;

destructor Destroy; override;

Published

  End;



and//A logical and said,

if (a>0) and (b>0) then


//Two, said bit operation

var

  A, B, c:  Integer;

begin

  c := (a and b);

End;


//The use of And logic,   And expression must use small parenthesis,   to avoid the conditions of conflict.

//For example:

if a>0 and b>0 then

//The compiler may understand:

if a>(0 and b)>0 then

//Or:

if (a>0) and (b>0) then

//But the actual compiler, the compiler generates a     conflict, reports the error.

//And the first kind may contain a> b>   C form, which is not supported in Delphi.

//So the use of the And operator must use parentheses to distinguish,   about the conditions.

//Said bit operations must also be in parentheses,   And and parameters including.



array//Array is used to represent an array,   any object can be declared as an array. The array is divided into 2 kinds of static and dynamic.


//Static array

var

  Arr1: array [1..10] of Integer;


//Dynamic arrays,   because I do not know when the number of the statement, the elements of   so must use SetLength method set in array in the late size

var

  Arr2: array of Integer;


//Array as a parameter,   not to the size of the array,   only into the array name,   and then use the Length method to obtain the number of elements in the array

function X(A: array of Integer): Integer;

var

 I:  Integer;

begin

  Result := 0;

  for i := 0 to Length(A)-1 do

  Result := Result + A[i];

End;



as//As used to convert an object to another

procedure BtnClick(SEnder:TObject);

begin

  (SEnder as TButton).Caption := 'Clicked';

End;


//For conversion, object filling interface must be carried out with the As  

(HTTPRIO as IExp).GetConnection;


//As cannot be used for conversion, data types of   the following code is wrong:

var

  I:  Integer;

  S:  string;

begin

  s := (i as string);

End;

//The correct term is:

s := string(i);



asm//The Asm keyword is used to insert the assembly code,   the use of assembly code,   you must use the ASM... End;   structure, rather than a begin... End;

function IntToHex(Value: Integer; Digits: Integer): string;

asm

  CMP  EDX, 32

  JBE  @A1

  xor  EDX, EDX

  @A1: PUSH ESI

  MOV  ESI, ESP

  SUB  ESP, 32

  PUSH ECX

  MOV  ECX, 16

  CALL CvtInt

  MOV  EDX, ESI

  POP  EAX

  CALL System.@LStrFromPCharLen

  ADD  ESP, 32

  POP  ESI

End;



assembler//The Assembler keyword is used to support the early compilation,   such as 80386.

//The difference between it and the Asm: Asm allows the use of Win32 assembly,   while Assembler only allows 80x86 assembly,   it does not allow the Invoke statement.

function IntToHex(AValue: Int64): string; assembler;



automated//Automated access specifier is used to describe a type of automatic members,   it can make the program version downward compatibility.

//Members of the ComObj unit and its example cannot use Automated access specifier.

type

  TDemo  =  class

automated

Str:WideString;

  End;


//  in the program for the next version,; will Str modifications,   a

type

  TDemo  =  class

automated

Str: AnsiString;

  End

//The new version of the Str variable to accept WideString data, old versions of   and automatically converted to AnsiString.

//  in the actual development,; if there is no special needs,   in general do not have automated access specifier.



begin//The begin keyword is used to indicate the beginning of a program, or a structure of   must come to an End with the End keyword.

Procedure  X;

begin

  ShowMessage('A Demo');

End;


//The general structure, such as If,     For,   While, also need to use the begin keyword to mark the starting point of structure

for i:=1 to 100 do

begin

  Sum : =  sum  +  I;;

  if sum > 1000 then Break;

End;



case//The Case statement is used to complete the selection condition,   Case statements selected object must be a sequence types, including integer,       enumeration type, character type and so on.

//The Case statement must be by the End of end, if not consistent,   can be added to Else to make the general selection.

function GetDays(AYear,AMonth: Integer): Integer;

begin

  case AMonth of

1,3,5,7,8,10,12: Result := 31;

4,6,9,11: Result := 30;

2: begin

if IsLeapYear(AYear) then

Result:=29

Else

Result:=28;

end;

  Else

Result:=0;

end;



cdecl 

//Cdecl is a function calling conventions,   it provides from the C or C++ written DLL function call must comply with the rules.

//It can be C or C++ data type conversion in Delphi.

//For example, the code in C++:

int X(int i)

{

  return i*2;

}


//This function is compiled in Demo.dll,   must be used for Delphi calls;:

function X(i: Integer): Integer; Cdecl; external 'Demo.dll';



class//The Class keyword is used to declare or inherit a class,   can also make the classes and interfaces and inheritance.

//In addition,   the Class keyword can also be used to declare that a class of general method,   method; the parent class can access the sub class from within.

type

  ClassDemo = class(TObject)

Private

Public

constructor Create;

  end;


//If the class statement,   then the method in the class and can be used in class, such as  :

type

  ClassA = class

private

public

procedure Y;

  end;


type

  ClassB = class(ClassA)

private

public

class procedure X;

  end;

//ClassA in the use of direct access to the ClassB X method

procedure ClassA.Y;

begin

  Self.X;

end;

//The parent class class subclass methods as the method call at this time.



const//The Const keyword is used to declare a constant,   use the const statement data will not be changed in the program.

//Can also be used to declare function parameters,   with parameter const specified does not allow changes in the function.

const MyFileName = 'Delphi';

const MyInteger = 100;


//Using the Const statement does not need the constant data types,   the system will automatically determine the type,   and automatic adjustment.

//Parameter in the function can not be changed using the const statement

function X(const i: Integer): string;

//At this point in the function in the process of operation,   I value can not be changed.



constructor//The constructor keyword is used to declare a class constructor,   when the class is instantiated,   we call this function

//The constructor is usually denoted by Create,   Create method to CreateWnd method has several classes.

type

  ClassDemo = class(TObject)

private

FValue:  Integer;

public

constructor Create;

  end;


constructor ClassDemo.Create;

begin

  fValue := 0;

end;



contains//The Contains keyword indicates a packet (Package) contains a file.

//Introduced with Contains file must be added to the package files,   it can be lost references to avoid key file.

package DATAX;

  requires

rtl, clx;

  contains

Db, DBLocal, DBXpress;

end.



default//The Default keyword is used to point out the default value of an attribute

//Property only ordered type allowed the existence of a default,   otherwise it must initialize attribute value in the constructor.

type

  ClassDemo = class

private

FValue:  Integer;

Published

Property  Value:  Integer  read  fValue  write  fValue  default  0;

  end;


//It can also point to a kind of default properties

property strings[IndeX:  Integer]: string read GetString write PutString; Default;



destructor//Destructor is used to identify the destructor,   the destructor is released in the class is invoked automatically.

//The destructor is only allowed to cover,   don't allow overloading. As the name of the destructor usually use Destroy.

type

  ClassDemo = class(TComponent)

public

destructor Destroy;override;

  end;


//The TComponent class also has a Destroy method,   so to rewrite it

//But if overloaded,     is not allowed, the following code is wrong:

destructor Destroy; overload;



dispid//The DispId keyword is used in DispInterface interface,   used to specify a specific adapter number.

//  in the DispInterface interface, serial number; adaptation must be unique,

//If you do not specify a DispId,   the system will automatically assign adapter number for the interface within each method.

//Method by adapting the number to access the DispInterface interface.

type

  IStringsDisp = dispinterface

['{EE05DFE2-5549-11D0-9EA9-0020AF3D82DA}']

property ControlDefault[IndeX:  Integer]: Olevariant dispid 0; default;

function Count: Integer; dispid 1;

property Item[Index: Integer]: Olevariant dispid 2;

procedure Remove(Index: Integer); dispid 3;

procedure Clear; dispid 4;

function Add(Item: Olevariant): Integer; dispid 5;

function _NewEnum: IUnknown; dispid -4;

  end;



dispinterface//DispInterface is used to declare a special adapter interface,   this adapter can accept the standard system interfaces of incoming and outgoing data.

//Interface DispInterface statement cannot be inherited,   can only be referenced.

//The DispInterface method can only be called,   and must be dynamic binding.

//Through the DispId interface inside Han distribution adapter number.

//DispInterface can only be used for the Windows platform,   if the development, under the Linux   this keyword is automatically blocked.

//Typically,   do not use DispInterface.


//Example please refer to DispId



div//Div is used to calculate the values for the integer quotient. Two numerical Div operation must have as integer,   the result is an integer.

var

  a,b,c:Integer;

begin

  A  =  20;  :: b  =  3;;

  c := a div b; {6}

end;



do//The Do keyword is used to For,   While,   On,     With statement, a specific structure


//The For statement:

for i := 1 to 100 do sum:=sum+i;


//The While statement:

while i < 100 do

begin

 Sum : =  sum  +  I;;

 Inc (I);

end;


//The On statement (exception handling):

try

 : i  =  StrToInt (s);

except

 On  exception  do  ShowMessage ('Error! ');

end;


//The With statement:

with Memo1.Lines do

begin

 Clear;

 Append ('abc');

 Append ('123');

end;



downto//The DownTo keyword is used to the For statement,   loop variable is decreasing.

for i := 100 downto 1 do

  ListBox1.Items.Add (IntToStr (I));


//  in the For statement, using the To keyword; the loop variable increases,   decreases; with the DownTo keyword.



dynamic//Dynamic is used to declare a method of dynamic,

//Dynamic methods can be overridden,   and it can make the code size is reduced as much as possible (from Virtual).

procedure X(i: Integer); dynamic;



Else//Else for running direction, guide the process of   it can and If,   Case and On statements associated with,   when the condition is not satisfied,   to run under Else


//The If statement (in the If statement,   else not allowed before the semicolon):

If  a  >   b  then

  c := a

else

  c:=b;


//The Case statement:

case Tag Of

  1:Result:=1;

  2:Result:=2;

  3:Result:=3;

else

  Result:=0;

end;


//The On statement (exception handling):

try

  : i  =  StrToInt (s);

Excpet

  on EZeroDivide do Result := 1;

  on EOverflow do Result := 2;

else

  Result := 0;

end;



end//End is used to end a statement block or a unit.

//It can be associated with begin,   Case,   Class,   Interface,   Asm,   Unit,   Package phase matching.

//The statement block (local end),   End must add a semicolon.

//And for the unit or package (the global end),   end must be added to an end.

//In the If statement before the else keyword End not allowed to add a symbol.

procedure X;

begin

 With  Button1  do

 begin

  If  Button1.ShowHint  then

   Button1.Caption : = 'Hinted';

  else

   Button1.Caption : = 'Not  Hinted';;

 end;

end;


//The use of End in the bag to the end:

package DATAX;

  requires

rtl,

clx;

  contains Db, DBLocal, DBXpress;

end.



except//The except keyword is used to exception handling,   must be used in a try statement,   if an exception occurs, the   will execute except statements;

try

  : i  =  StrToInt (s);

except

  ShowMessage('Error!');

end;



export//Export indicates the function calling convention,   it points out that the function can be output,   the output function can be local or remote calls.

//Other applications can use DLL function calls in the program. It is backwards compatible.

function Add(A, b:  Integer): Integer; export;


//If the program is compiled into a Demo.exe,   and another program calls to this function,   you can use the following statement

function Add(A, b:  Integer): Integer; stdcall; external 'Demo.exe';



exports//Exports is used to output object,   it must be used in between, and implement the interface   can output multiple items,   between items are separated by commas.

library Demo;


function X(i: Integer): string; stdcall;

begin

 Result:=IntToStr (I);

end;


exports

 X;


begin

end.


//If the output object is overloaded,   you must to assume an alias,   and specify the parameters.

library Demo;


function X(i: Integer): string; overload; stdcall;

begin

 : Result  =  IntToStr (I);

end;


function X(S:  string): Integer; overload; stdcall;

begin

 : Result  =  StrToInt (s);

end;


exports

  X(i: Integer) name 'x1',

  X(S:  string) name 'x2';


begin

end.



external//The External keyword is used to refer to an external or method OBJ.

{$L Demo.OBJ}

procedure X(i:Integer);external;


//If the reference, from the DLL or external program   you can use the following code:

function A(FileName: string): string; external 'Demo.dll';


//If the function is quoted to be overloaded,   must also pointed out; the name of the reference.

function A(Name: string): string; overload; stdcall; external 'Demo.dll' name 'A1';

function A(Code: Integer): string; overload; stdcall; external 'Demo.dll' name 'A2';


//The External keyword is used,   must pay attention to case,   otherwise, an error will occur.



far//Far indicates the function calling convention,   it points out that the function can be called remotely.

//Other applications can use DLL function calls in the program. It is backwards compatible.

function Add(A, b:  Integer): Integer; Far;


//If the program is compiled into a Demo.exe,   and the other one in the other computer programs need to call this function,   you can use the following statement:

function Add(A, b:  Integer): Integer; stdcall; external 'Demo.exe';



file//The File keyword indicates the file type, the   file must be declared as File;,

//If additional Of and file type, after File   the file can be defined as the read and write the specified data type.

type

  TPerson  =  record

PName:  string[32];

PAge:  Integer;

  end;

var

  PFile: file of TPerson;



finalization//The finalization keyword identifies the method unit is released to call,

//Usually release the object, automatic release not unit in the   also can not.

//Finalization most commonly used is to make the initialization of the OLE object.

initialization

  ActiveX.OleInitialize(nil);

finalization

  ActiveX.OleUninitialize;



finally//The finally keyword indicates the exception handling method must be called in the last,

//Regardless of whether there is abnormal,   finally statement always performed in the try statement at the end.

try

  Node : =  Node.GetNext;;

  Edit1.Text := Node.Text;

finally

 Node : =  nil;;

end;



for//The For keyword extraction For loop structure,   used for a specified number of cycles.

for i := 1 to 100 do Sum : =  sum  +  I;;


//If the loop variable is decreasing,   you can use the DownTo keyword

for i := 100 downto 1 do Inc(sum);



forward//The Forward keyword is used to pre define method. Define only method declarations,   and then the methods in the program's back.

//Do have readability, conducive to code   can be all together,   and then all of the implementation are put together.

function X(i: Integer): Integer; forward;

procedure Y(s: string); forward;

...

function X;

begin

  Result  =  i  * : 2;

end;


procedure Y;

begin

  WriteLn(s);

end;


//Method of using Forward in the realization of pre declaration does not need to be input method and the return value, the parameter   directly using the method name.



function//Function is used to declare a function

function X(i: Integer): Integer;


//It can also be used for dynamic function declaration

type

 TFun  =  function (i:  Integer):   Integer  of  object;


//Dynamic statement,   does not need to point out the function name,   only requires that the parameters and return type can be,   specific function name in the late binding.



goto//The Goto statement used in jump line,   you can jump to the current structure layer in any position.

//Must be declared with the label keyword in the declaration at the line numbers.

//Due to the structure, the Goto statement will destroy the program   is not recommended.

var

 A, b:  Integer;

label

 X, Y;

begin

 If  a  >   b  then

  Goto  X

 else

  Goto  Y;

X:

 WriteLn ('a  >   B');

Y:

 WriteLn ('b  >   A');

end;



if//The If keyword extraction If conditional statements,   for the judgment of the conditions.

var

 a,b: Integer;

begin

 A  =  2;  :: b  =  3;;

 If  a> b  then

  WriteLn ('a='  +  IntToStr (a))

 else

  WriteLn ('b='  +  IntToStr (b));

end;


//The structure of the If statement is usually If... Then... Else,   else statement can not.

//In a If statement if there are multiple sub statement,   you must End structure with begin... Are distinguished.

If  a  >   b  then

begin

 WriteLn ('a> B');

 WriteLn ('a='  +  IntToStr (a));

 WriteLn ('b='  +  IntToStr (b));

End

else

 WriteLn ('b> A');



implementation//Implementation identifies the implementation section, in the   cell; the basic structural unit for:

//Unit...Interface...implementation...end.

//The body of the function,   process must be written after the implementation keyword.

//If the reference object, after implementation   the object is not open,   can only supply unit itself.

implementation

  Uses  frmAbout;

begin

  FormAbout.Show;

end;


//A complete unit must have the implementation part.



implements//Implements points out that a property inheritance,   from the interface; this property is converted into the interface object.

//The interface dynamic binding attribute,   set property and dynamic values.

type

 IMyInterface  =  interface

  Procedure  P1;

  Procedure  P2;

 end;

 TMyImplclass  =  class

  Procedure  P1;

  Procedure  P2;

 end;

 TMyclass  =  class (TInterfacedObject,   IMyInterface)

  FMyImplClass:  TMyImplClass;

  Property  MyImplClass:  TMyImplclass  read  FMyImplclass  implements  IMyInterface;

  Procedure  IMyInterface.P1  =  MyP1;

  Procedure  MyP1;

 end;


//The implements statement,   in the class declaration that interface method of entity, such as in the example above  :

procedure IMyInterface.P1 = MyP1;



in//In is used for judging a collection contains an element. The judged content must be a single set of elements and a collection of examples.

type

 TCol  =  (cA, cB, cC);

 TCols  =  set  of  TCol;

var

 Cols:  TCols;

begin

 Cols : =  [cA, cB];;

 If  cA  in  Cols  then

  ShowMessage ('cA  in  Cols')

 else

  ShowMessage ('cA  not  in  Cols');

end;


//In is also used in the project file,   used to identify whether a file is referenced by the project.

Uses

 Unit1  in 'Unit1.pas';


//In can be used in a For statement,   used in cycle out of a set of elements.

var

 s: string;

 Sl:  TStringList;

begin

 ...

 For  s  In  sl  do

 begin

  ShowMessage (s);

 end;

end;



index//Index is used to identify the serial number, in the property   for attribute; the same methods (Get, Set) operate on different attributes.

type

 TForm1  =  class (TForm)

 private

  Function  GetInfo (const  Index:    Integer): Longint;

  Procedure  SetInfo (const  Index:  Integer;   const  Value:  Longint);

 public

  Property  iLeft:Longint  index  0  read  GetInfo  write  SetInfo;

  Property  iTop:Longint  index  1  read  GetInfo  write  SetInfo;

  Property  iWidth:Longint  index  2  read  GetInfo  write  SetInfo;

  Property  iHeight:Longint  index  3  read  GetInfo  write  SetInfo;

 end;


function TForm1.GetInfo(const Index: Integer): Longint;

begin

 Case  Index  of

  0:  result : =  self.Left;;

  1:  Result : =  self.Top;;

  2:  result : =  self.Width;;

  3:  result : =  self.Height;;

 end;

end;


//The Index keyword is also used in the property of multiple elements, and points out that the   for example:

property Selected[Index: Integer]: Boolean read GetSelected write SetSelected;



inherited//Inherited is used to invoke a method of the superclass.

type

 TDemo  =  class (TComponent)

 public

  Constructor  Create (AOwner:  TComponent;   override);

 end;


constructor TDemo.Create(AOwner: TComponent);

begin

 Inherited  Create (AOwner);;

end;


//If the call is the method, and its namesake   you can also save the method name and parameter such as in this example.

inherited Create(AOwner);

//Can be replaced:

Inherited;



initialization//The initialization keyword identifies the method unit is loaded to call,

//Usually, initialize some can not automatically initialized   also can not.

//Initialization most commonly used is to make initialization of the OLE object.

initialization

  ActiveX.OleInitialize(nil);

finalization

  ActiveX.OleUninitialize;



inline//The InLine keyword is used to Asm or assembler structure,

//For the assembly language statement is downward compatible. It does not have any effect on the compiler.

function IntToStr(Value: Integer): string;

asm

 InLine;

  PUSH  ESI

  MOV

ESI, ESP

  SUB

ESP, 16

  xor

ECX, ECX

  PUSH  EDX

  xor

EDX, EDX

  CALL  CvtInt

  MOV

EDX, ESI

  POP

EAX

  CALL  System.@LStrFromPCharLen

  ADD

ESP, 16

  POP

ESI

end;



interface//Interface identifies the interface part, in the   cell; the basic structural unit for:

//Unit...Interface...implementation...end.

//Function,   the process of the statement must be written after the Interface keyword.

//If the reference object, after Interface   the object is not an instance,   use must be instantiated.

Interface

 Uses  frmAbout;

var

 FAbout:  TFormAbout;

begin

 FAbout : =   TFormAbout.Create (Self);

 FAbout.Show;

end;


//A complete unit must have the Interface part.


//Interface can also be used as interface declarations.

type

 IMalloc  =  interface (IInterface)

 ['{00000002-0000-0000-C000-000000000046}']

  Function  Alloc (Size:  Integer):   Pointer;   stdcall;

  Function  Realloc (P:  Pointer;   Size:  Integer):   Pointer;   stdcall;

  Procedure  Free (P:  Pointer;   stdcall);

  Function  GetSize (P:  Pointer):   Integer;   stdcall;

  Function  DidAlloc (P:  Pointer):   Integer;   stdcall;

  Procedure  HeapMinimize;   stdcall;

 end;



is//The Is keyword is used for object judgment,   in some cases,   can also be used as "As".

var

 Comp:  TComponent;

begin

  ...

 If  Comp  Is  TEdit  then

  (Comp  as .Text  =  TEdit):'Edit';

end;



label//The label keyword is used to declare a number of labels,   to use Goto for steering,   is not recommended.

var

 a,b: Integer;

label

 X, Y;

begin

 if a > b then

  Goto  X

 else

  Goto  Y;

X:

 WriteLn ('a> B');

Y:

 WriteLn ('b> A');

end;



library//The Library keyword is used to point out a project for the library. The library after the compiler to generate DLL files,   can be called by other programs.

library Editors;

uses EdInit, EdInOut, EdFormat, EdPrint;

exports

  InitEditors,

  doneEditors name done,

  InsertText name Insert,

  DeleteSelection name Delete,

  FormatSelection,

  PrintSelection name Print,

  SetErrorHandler;

begin

  InitLibrary;

end.



message//The Message keyword is used to declare message method,

//Method with Message must be pointed out that the received message types,   and by reference to the message into the method,   for processing.

procedure Refresh(var Msg: TMessageRecordtype); message ID_REFRESH;


procedure Refresh(var Msg: TMessageRecordtype);

begin

  if Chr(Msg.Code) = #13 then

...

  else

inherited;

end;


//Users can customize the message,   a custom message can be received by the Message,   and trigger events.



mod//Mod is used to calculate the values of integers modulo   that is, the remainder. For two numerical Mod operation must have as integer,   the result is an integer.

var

 a,b,c: Integer;

begin

 a := 20; b := 3;

 C : =  a  mod  B;   {2};

end;



name//The Name keyword is used to point out the alias method,

//For a to be external reference method,   Name method; suggestions for alias,   solid content to avoid external program change method.

//References a method from the outside,   if the method has an alias,   it must be identified by Name.

function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; 

  stdcall; external 'user32.dll' name 'MessageBoxA';



near//Near indicates the function calling convention,   it points out that the function can be a local call.

//Other applications can use DLL function calls in the program. It is backwards compatible.

function Add(a,b: Integer): Integer; near;


//If the program is compiled into a Demo.exe,   and another in the local procedure calls to this function,   you can use the following statement:

function Add(a,b: Integer): Integer; stdcall; external 'Demo.exe';



nil//Nil is used to represent a null pointer,   or is no object instances.

while Node <> nil do

begin

 ListBox1.Items.Add (Node.Text);

 Node := Node.GetNext;

end;



nodefault//The NoDefault keyword indicates that a property is not allowed to have a default value,   this is commonly used in succession.

type

 TClassA  =  class

 private

  FValue:  Integer;

 published

  Property  Value:  Integer  read  fValue  write  fValue default 0;

 end;


 TClassB  =  class (TClassA)

 published

  Property  Value:Integer  read  fValue  write  fValue  NoDefault;

 end;


//We can see from the above example,   TClassA Value has a default value of 0,

//TClassB inherits from TClassA,   so also inherited from its default value,   in the NoDefault to remove the default value



not//Not is used to invert,   it denied the original results. For example:

if a > b then

//Can be written as:

if not(a < b) then


//The Not keyword is usually used for switching type Boolean

procedure Button1Click(Sender: TObject);

begin

 StatusBar1.Visible : =  not  StatusBar1.Visible;;

end;



object//Object is used to declare an object,   this object can be arbitrary,   and backward compatible with.Object can only be Object inheritance.

//Method and statement method declaration of the class of the object is the same.

type

 ODemoA  =  object

 end;


 ODemoB  =  object (ODemoA)

 end;


//The Object keyword is used to declare a dynamic function or process, such as  :

type

 TMyFun  =  function (i:  Integer):   Integer  of  Object;

 TMyProc  =  procedure (s:  string)   of  object;


//After the function or procedure object statement can be dynamically bound to the body of the function, the specified   or is bound to the control's event.



of//The key for Of and other key structure specified by the.Of and Case,   Class,   Array,   File,   Set,   Object.


//The Case statement:

case Tag Of

 0:  Result : = 'a';;

 1:  Result : = 'b';;

end;


//The Class statement:

type

 TDemo  =  class  of  TComponent;


//The structure of Array:

var

 MyInt:  array  of  Integer;


//The structure of File:

var

 MyFile:  file  of  Byte;


//The Set statement:

type

 TCol  =  (cA, cB, cC);

 TCols  =  set  of  TCol;


//The structure of Object:

type

 MyFun  =  function (I:  Integer):   Integer  of  Object;



on//The On keyword is used to exception handling,   points out the abnormal,   and gets the exception information.

try

 : i  =  StrToInt (s);

except

 On  E:  exception  do

  ShowMessage (E.Message);

end;



or//A, represents a logical or

if (a>0) or (b>0) then


//Two, said bit operation

var

  a,b,c: Integer;

begin

  c := (a or b);

end;


//The use of Or logic,   expression about Or must use small parenthesis,   to avoid the conditions of conflict

//If you use   in a conditional statement; Or,   the editor users do not know what to do with Or

For example:

if a>0 or b>0 then

//The compiler may understand:

if a>(0 or b)>0 then

//Or

if (a>0) or (b>0) then

//But the actual compilation,   the compiler will produce a conflict,   error report

//And the first kind may contain a> b>   C form, which is not supported in Delphi

//So the use of the Or operator must use parentheses to distinguish,   about the conditions.

//Said bit operations must also be in parentheses,   Or and parameters including.



out//The Out keyword indicates the output mode, method parameter   general function can return a value,

//The use of Out can return multiple results in a function.

//Out and VaR,   Out is to return the value of the form parameter returns,   and VaR is a parameter of the direct input address.

procedure X(out i: Integer; out s: string);

begin

 I  =  i  * : 2;

 S : =  s  + 'abc';;

end;


procedure TForm1.Button1Click(Sender: TObject);

var

 i: Integer;

 s: string;

begin

 : i  =  20;

 S : = 'xxx';;

 X (I, s);

end;



overload//The Overload keyword indicates for overloaded methods, namely the method name the same load  ,

//But the number of parameters,   a type or a different order,   consist of heavy this condition.

function X(i: Integer): string; overload;

function X(s: string): string; overload;


//  inherited from a parent class, subclass; if owned and the parent class the same method,   it also must be made by the overload overloaded,

//But such heavy must also meet the requirements of heavy load.

type

 TDemo  =  class (TComponent)

 public

  Procedure  CreateWnd (AOwner:  TWinControl;   overload);

 end;


//As in the example above, the   subclass methods have to;:

procedure CreateWnd; {Inherited from the parent class}

procedure CreateWnd(AOwner: TWinControl); {Sub class declaration}

//A total of two CreateWnd method.


//If you do not use a heavy load,   method can in subclasses override the parent class.



override//Override is used to cover a Virtual or Dynamic form.

//Coverage must be used by covering method statement,   and does not allow the modification of the original method parameters and return type.

procedure Create(AOwner: TComponent); override;


//Override used for inheritance,   off the superclass methods in subclasses.

type

 TClassA  =  class

  procedure X; virtual;

 end;


 TClassB  =  class (TClassA)

  Procedure  X;   override;

 end;


//As in the example above, the   subclass methods have to;:

procedure X; {Covering from the parent class}

//The superclass methods have to:

procedure X; {  parent class of its own, is not covered;}


//If the parent class method without Virtual or Dynamic statement,

//Or there is a need, modify the parameters of the   it must be covered with the Reintroduce keyword.



package//The Package keyword is used to point out a project for the control library.

//Control library compiled to generate BPL files,   can be mounted to the Delphi control library,   and the development of future use of controls.

package DATAX;

  requires

rtl,

clx;

  contains

MyUnit in 'C:\MyProject\MyUnit.pas';

end.



packed//The Packed keyword is used to record or array structure package,   package is packaged; the volume of the object can be significantly reduced.

type

 TPerson  =  packed  Record

  PName:  string[32];

  PAge:  Integer;

 end;

 MyArray:  packed  array  of  PChar;



pascal//Pascal indicates the function calling conventions,

//It points out that the function follows the Pascal reason, when called   first of all variables are initialized,

//Avoiding the asynchronous thread invocation errors. It is backwards compatible.

function X(i: Integer): Integer; Pascal;

begin

 Result  =  i  * : 2;

end;



private//Private indicates the within class access elements distinguish permission,   Private distinguish elements can only be the internal access.



procedure//Procedure is used to declare process

procedure X(i: Integer);


//It can also be used for dynamic function declaration

type

 TProc  =  procedure (i:  Integer)   of  object;


//Dynamic statement,   does not need to indicate the procedure name,   only need that parameters can be,   the specific procedure name in late binding.



program//The Program keyword is used to point out a project for the application program. Control library compiled to generate exe files,   can be executed directly;

program Project1;

uses

  Forms,

  Unit1 in 'Unit1.pas' ;

{$R *.res}

begin

  Application.Initialize;

  Application.CreateForm(TForm1, Form1);

  Application.Run;

end.




property//The Property keyword is used to declare a property,   attribute is divided into explicit and implicit attribute two,

//The only access specifier attribute declaration in published is the explicit attribute,   can be viewed directly in an object viewer.

type

 TDemo = class

 Private

  FValue:  Integr;

 Published

  Property  Value:  Integer  read  fValue write fValue;

 end;


//An event is, the attributes of   in published to distinguish the Property statement under

type

 TOnTextChange=procedure  (Sender:  TObject;   of  object);

 TDemo = class

 private

  FEvent:  TOnTexChange;

 published

  Property  OntextChange:  TOnTextChange  read  fEvent  write  fEvent;

 end;



protected//Protected indicates the within class access elements distinguish permission,   Protected distinguish the element can only be the inside of a class and its subclasses access.



public//Public indicates the within class access elements distinguish permission,   Public distinguish elements can be inner and outer any object access.



published//Published indicates the within class access elements distinguish permissions.

//The Published element can be distinguished by the inner and outer any RTTI object access

//Only in the Published declaration in distinguishing attribute operator can become explicit attribute and displayed in the object in the viewer.



raise//The Raise statement is used to throw an exception,

//If hope through the external program to handle the exception,   or if an exception occurs to the exception,   you can use the Raise statement.

function GetString(i: Integer): string;

begin

 If  i  <  0  then

  Raise  exception.Create ('Integer  Cannot  smaller  than  0');

 : Result  =  IntToStr (I);

end;


//  exception handling, can be re throw the exception;

try

 i := StrToInt(s);

except

 On  E:  exception  do

  Raise  exception.Create (E.Message);;

end;



read//Read for the member or method used in reading ID attribute.

private

 fValue: Integer;

published

 property Value: Integer read fValue;


//The example shows that the value of the Value attribute is read from the fValue members.



readonly//The ReadOnly keyword is used to identify an object is read-only.

property ReadOnly;


//When ReadOnly is set to True,   does not allow the user to manually modify the attribute,   can only be operated by other objects.



record//The Record keyword is used to declare a structure record,

//A structure can be considered as a no need to instantiate objects,   has its own members.

type

 TPerson = record

  PName: string[32];

  PAge: Integer;

 end;



register//Register indicates the function calling convention,   it points out that the function can be recorded in the registry in being invoked. It is backwards compatible.

function Add(a,b: Integer): Integer; Register; Register


//Keyword is used to control or IDE control register or expert tool.

procedure Register;

begin

 RegisterComponents ('Sample',   [TDemo]);

end;



reintroduce//Reintroduce is used to re release method,   is usually used when inheritance;,

//If the method is to cover the static method,   or need to modify the method parameters,   must be re issued by the Reintroduce.

//For the Virtual or Dynamic methods,   can be directly used Override coverage.

type

 TClassA  =  class

  procedure X;

 end;

 TClassB  =  class (TClassA)

  Procedure  X;   reintroduce;

 end;

 TClassC  =  class (TClassB)

  Procedure  X (i:  Integer;   reintroduce);

 end;



repeat//The repeat keyword is used to derive the repeat loop structure,

//The circulation must first perform a loop body,   and then the loop condition to judge.Repeat must be used in combination with the Until keyword.

i := 0;

repeat

 Sum : =  sum  +  I;;

 Inc (I);

until(i >= 100);



requires//The Requires keyword to specify that a necessary condition for compiling Package. If the Requires conditions are not met,   is not allowed to compile package.

package DATAX;

  requires

rtl,

clx;

end.



resourcestring//ResourceString is used to declare a resource string,   resource string can be used in structure is stated.

ResourceString

 CreateError  = 'Cannot  create  file %s';

 OpenError  = 'Cannot  open  file %s';

 LineTooLong  = 'Line  too  long';

 ProductName  = 'Borland  Rocks';

 SomeResourceString  =  SomeTrueConstant;



safecall//Safecall is a function calling conventions,   it provides the function call to COM must comply with the rules.

//  at compile time statement; function, Safecall is compiled into COM interface compatible.

procedure X(s: WideString); safecall;


//Be in after the compiler:

procedure X(s: PAnsiString);



set//The Set keyword is used to declare a collection class,   collection class allows for set operators, such as   in operation.

type

 TCol  =  (cA, cB, cC);

 TCols  =  set  of  TCol;


//Operation allows the use of addition and subtraction symbols to add or remove a set of elements

var

 Cols:  Tcols;

begin

 Cols : =  Cols  +  [cA, cB];;

end;



shl//SHL said the shift to the left,   left shift of the digit that is multiplied by 2 to the power

var

 x: Integer;

begin

 X : =  2  shl    {16}; 3;

end;



shr//SHR said the right shift, the shift is divided by the number of   2 to the power

var

 x: Integer;

begin

 X : =  16  shr    {4}; 2;

end;



stdcall//Stdcall is a function calling conventions,   it provides allows function program should abide by the rules.

//The Stdcall keyword must be paired is formed between the main parties and regulated.


//For example,   transfer function:

Library Demo;

function X(i: Integer): Integer; stdcall;

begin

 Result := i * 2;

end;

exports

 X;

begin

end.


//The main function:

function X(i: Integer): Integer; stdcall; external 'Demo.dll';


//At the same time the need to pay attention to the use of the Stdcall keyword, the    , the called function is case sensitive,   it is easy to make mistakes.



stored//Stored is used to indicate the value of an attribute can be retained,   if True is specified,   to allow for the property values are assigned undo operation.

property Value: string read fValue write fValue stored True;



string//String is a data type,   it represents the string.

var

 Str: string;



then//The Then keyword is used to   the If statement, If; when the condition is established,   after the Then statement.

var

 a,b: Integer;

begin

 if a > b then

  WriteLn ('a')

 else

  WriteLn ('b');

end;



threadvar//Threadvar identifies with a thread start and create variables,

//If you use Threadvar to declare a variable,   you must manually release the occupied space in the program before the end.

threadvar S: AnsiString;

S := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

S := '';


//S := ''; The variable S is releasing the memory.



to//The To keyword is used to the For statement,   loop variable is incremented.

for i := 10 to 100 do

 ListBox1.Items.Add(IntToStr(i));


//  in the For statement, using the To keyword; the loop variable increases,   decreases; with the DownTo keyword.



try//The try statement is used to exception handling,   for there may be unusual statement,   can be placed in the try structure,   in order to protect was conducted.

try

 i := StrToInt(s);

except

 ShowMessage ('Error');

end;



type//The Type keyword is used to declare a variety of objects,   objects, Type keyword to declare;   in the relay passed by reference.

type

 TDemo = class

 end;


//Type is also used to declare an enumeration type or is passed by reference variables.

type

 TCol  =  (cA, cB, cC);

 TInt  =  Integer;



unit//Unit identifies a unit at the beginning, the basic structural unit of   Unit...Interface...implementation...end.

Unit Unit1;

Interface

 Uses  Classes;

implementation

end.


//A complete unit must have Unit as the first.



until//The Until keyword is used to judge the condition of repeat loops,

//If the loop condition is true, then exit  .Until must be used in combination with the repeat keyword.

i := 0;

repeat

 sum := sum + i;

 Inc (I);

until(i >= 100);



uses//Uses is used to refer to an external unit,   and can use the public part of the unit.

//The Uses statement is usually put in a unit of the interface or.

Interface

 Uses  Classes;

Implemention

 uses frmAbout;



var//The VaR keyword is used to declare a variable or object,   VAR declared variables with values.

var

 i: Integer;

 s: string;


//Var can also be used for the identification method by reference parameters

function X(var i: Integer): Integer;


//The parameter I in the function that is passed by reference,   its value can be changed, the function implementation of   and returns.



Varargs

//VarArgs identifies a reference parameter,   it must be combined with the   and Cdecl keywords,; that function allows calls using pass by reference.

//The parameter list finally can have incoming parameters change quantity

function printf(Format: PChar): Integer; cdecl; varargs;


//The above code references the Printf function, the C++ class in the   and allow the parameters passed by reference method.



virtual//Virtual is used to declare a virtual method,

//A virtual method can be covered,   and it can make the process speed is as fast as possible (from Dynamic).

procedure X(i: Integer); virtual;



while//The While keyword is used to derive the While loop,   loop; first cycle conditions before the judge,   if the condition is true then execution loop.

i := 0;

while i < 100 do

begin

 sum := sum + i;

 Inc (I);

end;



with//The With keyword is used to the same object set up processing,   it can save the input a lot of duplicated code,   the code looks more streamlined.

with Form1.Memo1.Lines do

begin

 Clear;

 Append ('abc');

 Append ('def');

 SaveToFile ('C:\demo.txt');

end;


//The above code if you do not use the With statement,   very redundant copy content to the clipboard code:

Form1.Memo1.Lines.Clear;

Form1.Memo1.Lines.Append('abc');

Form1.Memo1.Lines.Append('def');

Form1.Memo1.Lines.SaveToFile('C:\demo.txt');



write//Write for the member or method used in writing the identifying attribute.

private

 fValue: Integer;

published

 Property  Value:  Integer  write  fValue;


//The example shows that the value of the Value attribute is written to the fValue member.



writeonly//The writeonly keyword is used to identify whether an object only write.

property writeonly;


//When writeonly is set to True,   does not allow the user to read attributes,   can only be operated by other objects.



xor//Xor is used for the XOR,   when the two operands are equal,   False   return, return True. unequal

var

 a,b: Integer;

begin

 A  =  2;  :: b  =  3;;

 If  a  xor  b  then

  WriteLn ('a  xor  B')

 else

  WriteLn ('a  not  xor  B');

end;


//Xor is also used to calculate the XOR

WriteLn(IntToStr(3 xor 5)); {6}


The original source: 


   Etc.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Lyle at February 06, 2014 - 10:22 AM