This article introduces in detail the names and usage of various keywords commonly used in Delphi for your reference in the programming process. Details are as follows:
absolute:
//It allows you to create a new variable, and the starting address of the variable is the same as another variable.var Str: string[32]; StrLen: Byte absoluteStr;//This declaration specifies the starting address of the variable StrLen and Str Same.//Since the 0th position of the string stores the length of the string, the value of StrLen is the length of the string.beginStr := 'abc';Edit1.Text := IntToStr(StrLen);end;
abstract:
//It allows you to create abstract methods, including classes with abstract methods called abstract classes. //Abstract keyword must be used together with Virtual or Dynamic keywords, because abstract methods must be overridden. //Abstract classes cannot Instantiation, abstract methods cannot contain method bodies. type TDemo = class private protected procedure X; virtual; abstract; public constructor Create; destructor Destroy; override; published end;
and:
//1. Express logical AND if (a>0) and (b>0) then//2. Express bit operation vara,b,c: Integer;beginc := (a and b);end;//Use And When expressing logic, the expressions around And must be enclosed in parentheses to avoid conflicts of conditions.//For example: if a>0 and b>0 then//The compiler may understand it as: if a>( 0 and b)>0 then//or:if (a>0) and (b>0) then//But when actually compiling, the compiler will generate a conflict and report an error.//And the first one may include the form of a>b>c, which is in Delphi Not supported.//So you must use parentheses when using the And operator to distinguish the left and right conditions.//When expressing bit operations, you must also add parentheses to enclose And and the left and right parameters.
array:
//Array is used to represent arrays, and any object can be declared as an array. Arrays are divided into two types: static and dynamic. //Static array varArr1: array [1..10] of Integer;//Dynamic array, because The number of elements is not known at the time of declaration, so the size of the array must be set later using the SetLength method varArr2: array of Integer;//When the array is used as a parameter, the size of the array cannot be passed in. You can only pass in the array name, and then use the Length method to get the number of elements in the array function X(A: array of Integer): Integer;vari: Integer;beginResult := 0;for i := 0 to Length(A)-1 doResult := Result + A[i];end;
as:
//As is used to convert one object to another object procedure BtnClick(Sender:TObject);begin (Sender as TButton).Caption := 'Clicked';end;//For the conversion of the object filling interface, As must be used (HTTPRIO as IExp).GetConnection;//As cannot be used for data type conversion, the following code is wrong: vari: Integer;s: string;begins := (i as string);end;//The correct way to write it is: s := string(i);
asm:
//The Asm keyword is used to insert assembly code. When using assembly code, you must use the asm...end; structure instead of 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 ESIend;
assembler:
//The Assembler keyword is used to support early assembly, such as 80386, etc. //The difference between it and Asm: Asm allows Win32 assembly, while Assembler only allows 80x86 assembly, and it does not allow the Invoke statement. function IntToHex(AValue: Int64): string; assembler;
automated:
//Automated access specifier is used to describe an automatically typed member, which can make the program version backward compatible. //Members and their instances in the ComObj unit cannot use Automated access specifier.type TDemo = class automated Str:WideString ; end;//In the next version of the program, Str is modified and becomes typeTDemo = classautomatedStr: AnsiString;end//The new version of the Str variable can accept the old version of WideString type data, And automatically converted into AnsiString.//In actual development, if there is no special need, the automated access separator is generally not used.
begin:
//The begin keyword is used to indicate the beginning of a program or a structure, and must be ended with the end keyword. procedure You also need to use the begin keyword to mark the starting point of the structure for i:=1 to 100 dobeginsum := sum + i;if sum > 1000 then Break;end;
case:
//Case statement is used to complete conditional selection. The selected object of Case statement must be an ordered type, including integer type, enumeration type, character type, etc. //Case statement must be ended by end, if there is no matching selection item, else can be added to make a general choice. 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 type of function calling agreement, which stipulates the rules that must be followed when calling functions from a DLL written in C or C++. //It can convert data types in C or C++ to Delphi.//For example Code in C++: int X(int i){ return i*2;}//This function is compiled in Demo.dll. When calling with Delphi, you must use: function 'Demo.dll';
class:
//The Class keyword is used to declare or inherit a class, or the class and interface can be inherited at the same time. //In addition, the Class keyword can also be used to declare common methods of a class, so that the parent class can access the methods of the subclass from within the class. .type ClassDemo = class(TObject) private public constructor Create; end;//If a method is declared with class, the method can be used in both the class and related classes, for example: typeClassA = classprivatepublicprocedure Y;end;typeClassB = class(ClassA)privatepublicclass procedure method to call.
const:
//The Const keyword is used to declare constants. Data declared with const cannot be changed in the program. //It can also be used to declare function parameters. Parameters specified with const are not allowed to be changed in the function. const MyFileName = 'Delphi ';const MyInteger = 100;//When declaring a constant with Const, you do not need to indicate its data type. The system will automatically determine the type and make automatic adjustments.//You can use const to declare unchangeable parameters in a function function X(const i: Integer): string;//At this time, the value of i cannot be changed during the function operation.
constructor:
//The constructor keyword is used to declare the constructor of a class. When the class is instantiated, this function is first called. //The constructor is generally represented by Create. The Create method can be associated with the CreateWnd method that exists in the class.type ClassDemo = class( TObject) private fValue: Integer; public constructor Create; end;constructor ClassDemo.Create;beginfValue := 0;end;
contains:
//The Contains keyword indicates whether a package (Package) contains a certain file. //Files introduced with Contains must be added to the package file, which can avoid the loss of references to key files. package DATAX; requires rtl, clx ; contains Db, DBLocal, DBXpress;end.
default:
//Default keyword is used to indicate the default value of a property //Only ordered type properties allow the existence of default values, otherwise the property value must be initialized in the constructor. type ClassDemo = class private fValue: Integer; published property Value : Integer read fValue write fValue default 0; end;//It can also point out the default property of a class property strings[Index: Integer]: string read GetString write PutString; Default;
destructor:
//Destructor is used to identify the destructor, which is automatically called when the class is released. //The destructor is only allowed to be overwritten, and no overloading is allowed. The destructor usually uses Destroy as the function name. type ClassDemo = class( TComponent) public destructor Destroy;override; end;//Since there is also a Destroy method in the TComponent class, it needs to be rewritten//But if you want to overload the destructor, it is not allowed. The following code is wrong: destructor Destroy; overload;
dispid:
//The DispId keyword is used in the DispInterface interface to specify a specific adaptation serial number. //In the DispInterface interface, the adaptation serial number must be unique. //If DispId is not specified, the system will automatically assign the adaptation The serial number is given to each method in the interface. //You can access the methods in the DispInterface interface through the adaptation serial number. 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 specific adapter interface. This adapter can accept incoming and outgoing data in the standard system interface. //The interface declared with DispInterface cannot be inherited and can only be referenced. //The methods in DispInterface can only Called, and must be dynamically bound. //You can use DispId to assign an adaptation serial number to the interface. //DispInterface can only be used on the Windows platform. If you develop under Linux, Then this keyword will be automatically blocked by the system. //Normally, DispInterface is not used. //For examples, see DispId
div:
//Div is used to find the integer quotient of two numbers. The two values used in the Div operation must both be integers, and the operation results are also integers. var a, b, c: Integer; begin a := 20; b := 3; c := a div b; {6}end;
do:
//The Do keyword is used in For, While, On, With statements to form a specific structure //For statement: for i := 1 to 100 do sum:=sum+i;//While statement: while i < 100 dobegin sum := sum + i; Inc(i);end;//On statement (exception handling):try i := StrToInt(s);except on exception do ShowMessage('Error!');end;//With statement :with Memo1.Lines dobegin Clear; Append('abc'); Append('123');end;
downto:
//DownTo keyword is used in the For statement to indicate that the loop variable is decremented. for i := 100 downto 1 doListBox1.Items.Add(IntToStr(i));//In the For statement, the To keyword is used to increment the loop variable , use the DownTo keyword to decrement.
dynamic:
//Dynamic is used to declare a dynamic method. //Dynamic methods can be overridden and can reduce the code size as much as possible (different from Virtual).procedure X(i: Integer); dynamic;
else:
//else is used to guide the running direction of the program. It can be used in conjunction with If, Case and On statements. When the condition is not met, go to the else to run //If statement (in the If statement, no points are allowed before else. No.):if a > b thenc := aelsec:=b;//Case statement: case Tag Of1:Result:=1;2:Result:=2;3:Result:=3;elseResult:=0;end;//On statement (exception handling):tryi := StrToInt(s);Excpeton EZeroDivide do Result: = 1;on EOverflow do Result := 2;elseResult := 0;end;
end:
//End is used to end a statement block or a unit. //It can match begin, Case, Class, Interface, Asm, Unit, Package, etc. //For statement blocks (local end), End must be added after Semicolon.//For units or packages (global end), a period must be added after end.//No symbols are allowed after End before the else keyword in the If statement. Procedure X; begin with Button1 do begin if Button1. ShowHint then Button1.Caption := 'Hinted' else Button1.Caption := 'Not Hinted'; end;end;//Use End in the package to end: package DATAX;requiresrtl,clx;contains Db, DBLocal, DBXpress;end.
except:
//The except keyword is used for exception handling and must be used within the try statement. If an exception occurs, the statement after except is executed try i := StrToInt(s);except ShowMessage('Error!');end;
export:
//Export indicates the function calling protocol, indicating that the function can be exported, and the exported function can be called locally or remotely. //Other programs can call functions in the program in the form of dll. It is backward compatible. function Add( a,b: Integer): Integer; export;//If this program is compiled as Demo.exe, and another program needs to call this function, you can use the following statement function Add(a,b: Integer): Integer; stdcall; external 'Demo.exe';
exports:
//exports is used to output objects. It must be used between the interface and the implementation. Multiple items can be output at the same time, separated by commas. libraryDemo;function X(i: Integer): string; stdcall;begin Result:=IntToStr(i);end;exports X(i: Integer): string; overload; stdcall;begin Result := IntToStr(i);end;function X(s: string): Integer; overload; stdcall;begin Result := StrToInt(s);end;exportsX (i: Integer) name 'x1',X(s: string) name 'x2';beginend.
external:
//The External keyword is used to reference an external or method within OBJ.{$L Demo.OBJ}procedure X(i:Integer);external;//If it is referenced from a dll or external program, it can be used The following code: function A(FileName: string): string; external 'Demo.dll';//If the referenced function is overloaded, the referenced name must be additionally specified. function A(Name: string): string; overload ; stdcall; external 'Demo.dll' name 'A1'; function A(Code: Integer): string; overload; stdcall; external 'Demo.dll' name 'A2';//When using the External keyword, you must pay attention to the case , otherwise an error will occur.
far:
//Far indicates the function calling protocol, indicating that the function can be called remotely. //Other programs can call functions in the program in the form of dll. It is backward compatible. functionAdd(a,b: Integer): Integer; Far ;//If this program is compiled into Demo.exe, and another program on another computer needs 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 operation type. The file must be declared as File. //If Of and the file type are appended after File, the file can be defined to read and write specified type of data.type TPerson = record PName: string[ 32]; PAge: Integer; end;var PFile: file of TPerson;
finalization:
//The finalization keyword identifies the method to be called when the unit is released. //Usually it releases objects in the unit that cannot be automatically released. It may not be used. //The most commonly used case of finalization is to de-initialize OLE objects. initialization ActiveX.OleInitialize(nil);finalization ActiveX.OleUninitialize;
finally:
//The finally keyword indicates the last method that must be called in exception handling. //Regardless of whether an exception occurs, the statement after finally is always executed at the end of the try statement. try Node := Node.GetNext; Edit1.Text := Node.Text;finally Node := nil;end;
for:
//The For keyword leads to the For loop structure, which is used to perform a specified number of loops. for i := 1 to 100 dosum := sum + i;//If the loop variable is decrementing, you can use the DownTo keyword for i: = 100 downto 1 do Inc(sum);
forward:
//The Forward keyword is used for forward definition of methods. Only define the method declaration, and then implement the method later in the program. //This is beneficial to the readability of the code, and all declarations can be put together. Then put all the implementations together. function X(i: Integer): Integer; forward;procedure Y(s: string); forward;...function X;begin Result := i * 2;end;procedure Y;beginWriteLn(s);end;//Forward pre-declared methods do not need to enter the parameters and return values of the method when implementing it, just use the method name directly.
function:
//Function is used to declare functions function For the function name, you only need to indicate the parameters and return type. The specific function name can be bound later.
goto:
//The Goto statement is used to jump to a line number, which can jump to any position within the current structure layer. //The line number must be declared with the label keyword at the declaration. //Since the Goto statement will destroy the structure of the program, it 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:
//If keyword leads to If conditional statement, which is used to judge the condition.var a,b: Integer;begin a := 2; b := 3; if a>b then WriteLn('a=' + IntToStr(a )) else WriteLn('b=' + IntToStr(b));end;//The usual structure of the If statement is If...Then...else, the else statement is optional.//If there is any in the If statement Multiple sub-statements, Then you must use the begin...End structure to distinguish. if a > b thenbegin WriteLn('a>b'); WriteLn('a=' + IntToStr(a)); WriteLn('b=' + IntToStr(b) );Endelse WriteLn('b>a');
implementation:
//Implementation identifies the implementation part in the unit. The basic structure of the unit is ://Unit...Interface...implementation...end.//The function body, process body, etc. must be written after the implementation keyword./ /If the object is referenced after implementation, the object is non-public and can only be used by the unit itself. Implementation uses frmAbout;begin FormAbout.Show;end;//A complete unit must have an implementation part.
implements:
//Implements points out that a property is inherited from the interface. At this time, the property is converted into an interface object. //Dynamic binding of properties through the interface and dynamic setting of property 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;//After declaration through implements, you can point out the entity of the method in the interface when the class is declared, as in the above example: procedure IMyInterface.P1 = MyP1;
in:
//In is used to determine whether a set contains an element. The content to be determined must be a single set element and an instance of a set. 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 project files, Used to identify whether a file is referenced by the project. Uses Unit1 in 'Unit1.pas'; //In can be used in the For statement to loop out elements in a collection. 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 attribute so that the same attribute method (Get, Set) can be used to operate 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 to indicate multiple elements in properties, for example: property Selected[Index: Integer]: Boolean read GetSelected write SetSelected;
inherited:
//Inherited is used to call the parent class's method.type TDemo = class(TComponent) public constructor Create(AOwner: TComponent); override; end;constructor TDemo.Create(AOwner: TComponent);begin inherited Create(AOwner);end; //If you are calling a method with the same name as itself, you can also omit the method name and parameters. For example, inherited in the above example Create(AOwner);//can be changed to:Inherited;
initialization:
//The initialization keyword identifies the method to be called when the unit is loaded. //Usually it is used to initialize some objects that cannot be automatically initialized, but it does not need to be used. //The most commonly used case of initialization is to initialize OLE objects. initialization ActiveX. OleInitialize(nil);finalization ActiveX.OleUninitialize;
inline:
//The InLine keyword is used in the Asm or assembler structure, //It is used to indicate that the assembly statement is downward compatible. It has no impact on the compilation of the program. 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 ESIend;
interface:
//Interface identifies the interface part in the unit. The basic structure of the unit is://Unit...Interface...implementation...end.//Declarations of functions, procedures, etc. must be written after the Interface keyword./ /If the object is referenced after the Interface, the object has no instance and must be instantiated when used. Interface uses frmAbout;var FAbout: TFormAbout;begin FAbout := TFormAbout.Create(Self); FAbout.Show;end;//A complete unit must have an Interface part.//Interface can also be used as a declaration of an interface.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:
//Is keyword is used for object judgment. In some cases, it can also be used as "As".var Comp: TComponent;begin ... if Comp Is TEdit then (Comp as TEdit).Text := 'Edit ';end;
label:
//label keyword is used to declare the line number label so that Goto can be used for steering. It is not recommended to use.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:
//Library keyword is used to indicate that a project is a class library. The class library generates a DLL file after compilation, which 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 methods. //The method with Message must indicate the type of message received, and pass the message into the method by reference for processing.procedure Refresh(var Msg: TMessageRecordtype); messageID_REFRESH; procedure Refresh(var Msg: TMessageRecordtype);beginif Chr(Msg.Code) = #13 then...elseinherited;end;//Users can customize messages, Custom messages can also be received by Message and trigger events.
mod:
//Mod is used to find the integer modulus of two numbers, that is, the remainder. The two values used in the Mod operation must both be integers, and the results of the operations must also be integers. var a, b, c: Integer; begin a := 20; b := 3; c := a mod b; {2}end;
name:
//The Name keyword is used to indicate the alias of a method. //For a method to be referenced externally, it is recommended to use Name to apply for a method alias to prevent external programs from changing the entity content of the method. //When referencing a method from the outside, if 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 marks the function calling protocol, indicating that the function can be called locally. //Other programs can call functions in the program in the form of dll. It is backward compatible. function Add(a,b: Integer): Integer; near;//If this program is compiled into Demo.exe, and another local program needs to call 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 an object without an instance. while Node <> nil dobegin ListBox1.Items.Add(Node.Text); Node := Node.GetNext;end;
nodefault:
//The NoDefault keyword indicates that a property does not allow a default value, which is usually used in inheritance. 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;//As can be seen from the above example, Value in TClassA has a default value of 0, //TClassB inherits TClassA, so it also inherits its default value. Use NoDefault to remove the default value here.
not:
//Not is used to negate, it negates the original result. For example: if a > b then//It can be written as: if not (a < b) then//The Not keyword is usually used to switch the Boolean attribute 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 is backward compatible. Object can only be inherited by Object. //The method of declaring an object is the same as the method of declaring a class. type ODemoA = object end; ODemoB = object(ODemoA) end;//The Object keyword is also used to declare dynamic functions or procedures, for example: type TMyFun = function(i: Integer): Integer of Object; TMyProc = procedure(s: string) of object;//The function or procedure declared by object can be dynamically bound to the specified function body, or bound to the control event.
of:
//Of key is used to form a specified structure with other keywords. Of can be used with Case, Class, Array, File, Set, Object. //Case statement: case Tag Of 0: Result := 'a'; 1: Result := 'b';end;//Class statement: type TDemo = class of TComponent;//Array structure: var MyInt: array of Integer;//File structure: var MyFile: file of Byte;//Set statement: type TCol = (cA,cB,cC); TCols = set of TCol;//Object structure: type MyFun = function(I: Integer): Integer of Object;
on:
//On keyword is used for exception handling, pointing out the exception that occurred, and obtaining exception information. try i := StrToInt(s);except on E: exception do ShowMessage(E.Message);end;
or:
//1. Express logical or if (a>0) or (b>0) then//2. Express bit operation vara,b,c: Integer;beginc := (a or b);end;//Use Or When expressing logic, the expressions around Or must be enclosed in parentheses to avoid conflicts with conditions //If you use Or in a conditional statement, the editor does not know what the user is doing with Or. For example: if a>0 or b>0 then//The compiler may understand it as: if a>(0 or b)>0 then//or if (a>0) or (b>0) then//But when actually compiling, the compiler will generate a conflict , report an error //And the first one may contain the form a>b>c, which is not supported in Delphi //So you must use parentheses when using the Or operator to distinguish the left and right conditions.//Indicates bit operations Parentheses must also be added when Enclose Or and the left and right parameters.
out:
//The Out keyword describes the output method of method parameters. A general function can only have one return value. //Use Out to return multiple results in a function. //Out is different from var. Out returns a value. The form returns parameters, and var is the address of a parameter that is directly entered. procedure TForm1.Button1Click(Sender: TObject);var i: Integer; s: string;begin i := 20; s := 'xxx'; X(i,s);end;
overload:
//The Overload keyword indicates the method for overloading. Overloading means that the method name is the same, //but the number, type or order of parameters are different. If this condition is met, it constitutes an overload. function X(i: Integer): string; overload;function The requirements for overloading must be met.type TDemo = class(TComponent) public procedure CreateWnd(AOwner: TWinControl); overload; end;//As in the above example, the method owned by the subclass is: procedure CreateWnd; {Inherited from parent class}procedure CreateWnd(AOwner: TWinControl); {Subclass declaration }//There are two CreateWnd methods.//If overloading is not used, the method of the parent class can be overridden in the subclass.
override:
//Override is used to override a method in the form of Virtual or Dynamic. //When overriding, the declaration of the overridden method must be used, and the parameters and return type of the original method are not allowed to be modified. procedure Create(AOwner: TComponent); override;/ /Override is mostly used for inheritance, using subclasses to override parent class methods. type TClassA = class procedure X; virtual; end; TClassB = class(TClassA) procedure X; override; end;//As in the above example, The methods owned by the subclass are: procedure X; {overridden from the parent class}//The methods owned by the parent class are: procedure Statement, //or if there is a need to modify parameters, it must be overridden with the Reintroduce keyword.
package:
//Package keyword is used to indicate that a project is a control library. //The control library generates a BPL file after compilation, which can be installed into the Delphi control library so that the control can be used in future development. package DATAX; requires rtl, clx ; contains MyUnit in 'C:/MyProject/MyUnit.pas';end.
packed:
//Packed keyword is used to pack structure records or arrays. After packaging, the size of the packed object can be significantly reduced. type TPerson = packed Record PName: string[32]; PAge: Integer; end; MyArray: packed array of PChar;
pascal:
//Pascal marks the function calling protocol, //points out that the function follows Pascal when calling, that is, initializes all variables first, //avoids errors caused by asynchronous thread calls. It is backward compatible. function X (i: Integer): Integer; Pascal;begin Result := i * 2;end;
private:
//Private indicates the access differentiation permissions of elements within the class. Elements distinguished by Private can only be accessed within this class.
procedure:
//Procedure is used to declare procedure procedure Just point out the parameters, and the specific procedure name can be bound later.
program:
//Program keyword is used to indicate that a project is an application. The exe file is generated after the control library is compiled, and the program can be executed directly 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 properties. Properties are divided into explicit properties and implicit properties. //Only properties declared under the published access separator are explicit properties and can be viewed directly in the object viewer. type TDemo = class Private fValue: Integr; Published property Value: Integer read fValue write fValue; end;//Events are also a type of property and can be declared with Property under the published separator 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 access permissions of elements within the class. Elements distinguished by Protected can only be accessed within this class and its subclasses.
public:
//Public indicates the access differentiation permissions of elements within the class. Elements distinguished by Public can be accessed by any object within the class and outside the class.
published:
//Published indicates the access permissions of elements within the class. //Elements distinguished by Published can be accessed by any RTTI object within the class and outside the class. //Only attributes declared under the Published separator can become explicit attributes and Shown in Object Viewer.
raise:
//The Raise statement is used to throw exceptions. //If you want to handle the exception through an external program, or re-throw the exception when an exception occurs, 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;//In exception handling, the exception can be re-thrown try i := StrToInt(s);except on E: exception do raise exception.Create(E.Message);end;
read:
//Read is used to identify the member or method used to read the property. private fValue: Integer; published property Value: Integer readfValue; //The above example shows that the value of the Value property is read from the fValue member.
readonly:
//The ReadOnly keyword is used to identify whether an object is read-only.propertyReadOnly;//When ReadOnly is set to True, users are not allowed to manually modify properties and can only operate through other objects.
record:
//The Record keyword is used to declare a structure record. //A structure can be regarded as an object that does not need to be instantiated and has its own members.type TPerson = record PName: string[32]; PAge: Integer; end ;
register:
//Register marks the function calling protocol, indicating that the function can leave a record in the registry when it is called. It is backward compatible. functionAdd(a,b: Integer): Integer; Register; Register//Keywords also Used to register controls or expert tools with the control library or IDE.procedure Register;begin RegisterComponents('Sample', [TDemo]);end;
reintroduce:
//Reintroduce is used to re-publish methods, usually when inheriting. //If the method to be overwritten is a static method, or the parameters of the method need to be modified, etc., Reintroduce must be used to re-publish. //For Virtual or Dynamic methods, You can directly use Override to override. 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 introduce the repeat loop structure. //The loop must first execute the loop body once, and then judge the loop condition. repeat must be used in conjunction with the Until keyword. i := 0;repeat sum := sum + i; Inc(i);until(i >= 100);
requires:
//The Requires keyword points out the necessary conditions for compiling the Package. If the conditions of Requires are not met, the package is not allowed to be compiled. package DATAX; requires rtl, clx;end.
resourcestring:
// ResourceString is used to declare the resource string. The resource string can use .RsourceString Createrror = 'Cannot Create File %s'; OpenNot Open File %s'; oo Long' ; ProductName = 'Borland Rocks'; someResourceString = someTrueConstant;
SafeCall:
// SafeCall is a type of function call protocol. It stipulates that when the functions that are called by the COM must follow and the rules .// When compiling, the function declared by the SafeCall is compiled into a .proceDure X (s: widestRing) ; SafeCall; // After compiling, it becomes: procedure x (s: Pansistring);
set:
// The set keyword is used to declare the set class, and the set class allows the set operator to operate with a collection operator, such as in, etc. Let's add or delete a collection element Var color: tcols; begin color: = color + [ca, cb]; end;
SHL:
// SHL means shifting to the left, and the number of left moves is multiplied by the number of power VAR X: Integer; begin x: = 2 shl 3; {16} end;
SHR:
// SHR means shifting to the right, and the number of right shifts is divided by the number of power of 2 VAR X: Integer; Begin X: = 16 SHR 2; {4} End;
stdcall:
// STDCall is a type of function call protocol. It specifies the rules that the function that can allow the program calls .//Stdcall Keywords must form pairing between the main prescription and the preparation. Pharmaceutical function: library demo; function x (I: Integer): Integer; Stdcall; Begin Result: = i * 2; END; EXPORTS X; Beginend .// The main function: Function x (i: I: Integer): Integer; Stdcall; External 'Demo.dll'; // At the same time, pay attention. When using the stdcall keyword, the adjustment function is sensitive and prone to errors.
Stored:
// Stored is used to point out whether the value of a attribute can be retained. If True is specified, it allows the operation of the attribute value to be assigned to the attribute value.
string:
// String is a data type, which represents the string .var str: string;
then:
// The keywords are used in IF statements. When IF conditions are established, the statements after the then .var a, B: Integer; Begin if a> B the writel ('a') else writeln ('B'); end;
Threadvar:
// Threadvar identifies a variable created by a follow -up thread. // If the ThreadVar declares variables, it must be manually released by the space it takes manually before the program ends .threadvar s: Ansistring; s: = 'abcdefghijklmnopqrstuvwxyz'; s: = ''; // s: = ''; that is, release the memory occupied by the variable S.
to:
// to keywords for the for statement, indicating that the cycle variable is increasing .for: = 10 to 100 do listbox1.Items.add (INTTOSTR (i)); Words, use DOWNTO keywords.
try:
// Try statement is used for abnormal processing. For statements that may occur, it can be placed under the TRY structure so that it can protect it abnormally .try I: = Strtoint (s); Except Showmessage ('ERROR'); End;
Type:
// Type keywords are used to declare various objects, and the objects of the Type keywords are declared. When passing, pass the reference .Type tdemo = class end; // Type is also used to declare the enumeration type or variable according to reference variables .Type tcol = (CA, CB, CC); tint = Integer;
Unit:
// Unit identifies the beginning of the unit. The basic structure of the unit is unit ... interface ... iMplementation ... End.Unit Unit1; interface users classs; ImplementationEND .// A complete unit must have unit as the beginning.
undil:
// Until Keywords are used to determine the circular conditions of the Repeat cycle structure. // If the circulation conditions are true, the exit of the circulation. Intil must be combined with the repeat keyword. II: = 0; Repeat Sum: = Sum + i; INC (i); indil (i> = 100);
USES:
// Usees is used to quote an external unit, and can use the public part of the unit .//uses statement is usually placed in an interface of a unit or implementing parts .interface uses classs;
var:
// VAR keywords are used to declare a variable or object, and transmit the variable connection value by VAR statement .var I: Integer; s: string; // VAR can also be used to identify the parameter parameter of the reference method parameter. I: Integer): Integer; // The parameters in the above function I are passed according to reference. Its value can be changed during the function execution and returns the main function function.
Varargs:
// Varargs identifies the reference parameter, which must be used with CDECL keywords, indicating that the allowable call function can be passed by reference. Format: PCHAR: Integer; CDECL; Varargs; // The above code is from the library of C ++ class libraries. Quoting the Printf function and allowed to pass the parameters as referenced.
virtual:
// Virtual is used to declare a virtual method, // The deficiency method can be covered, and it can make the program run fast as fast as possible (different from Dynamic) .proceDure x (I: Integer); virtual;
While:
// While keywords are used to lead to the WHILE cycle statement. Before the cycle, the cycle conditions are judged. ; End;
with:
// With keywords are used to process the same objects, which can save a large number of repeated code, making the code look more streamlined. With form1.lines dobegin clear; APPEND ('ABC'); 'DEF'); Savetofile ('C: /Demo.txt'); End; // The code above It looks 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 is used to identify the members or methods used in the logo attribute. PRIVATE FVALUE: Integer; PublicHISHED Property Value: Integer writefvalue; // The above example indicates the value of the value attribute.
Writeonly:
// Writeonly keywords are used to identify whether an object is only written .property writeonly; // When writingonly is set to true, users are not allowed to read attributes, and can only be operated by other objects.
xor:
// XOR is used to take differences or, when the two operations are equal, return to false, and return true.var a, b: integer; begin a: = 2; b: = 3; if a xor b the writeln ('A XOR B') Else Writeln ('A Not XOR B'); End; // XOR is also used to calculate the difference or value Writln (Inttostr (3 xor 5)); {6}