Space (#32) and control character (#0 to #31, where #13 is the carriage return or line terminator) are called blank characters (blank ).
Special symbols are non-literal and numeric characters, or a combination of these characters, they have a fixed meaning.
'[' Equivalent '(. ','] 'is equivalent '.) ';' (* 'and' *) 'are equivalent to' {'and'} '(indicating comment) respectively ).
,! (Exclamation point), "(double quotation marks), % (percent ),? (Question mark), \ (backslash), _ (underline), | (channel), and ~ (Broken down
Is not a special symbol
$ Prefix indicates a hexadecimal number, for example, $ 8F.
A tag is an Arabic sequence of no more than four digits, that is, from 0 to 9999. it is meaningless to start with 0.
. If there is no content ('') in single quotes, it is called a null string ). In a quote string, two consecutive single quotes ('') indicate one character, that is, the single quotes themselves (') control string consists of one or more control characters (control characters) each controller contains a # followed by an unsigned integer (10
Hexadecimal or hexadecimal). The integer ranges from 0 to 255, indicating the corresponding ASCII characters. The following control string
#89 #111 #117
It is equivalent to a reference string.
'You'
The operators include: @ not ^ */div mod and shl shr as +-or xor = ><><=> = in and is.
The behavior of some operators varies according to the data types passed to them. For example, when the not operator is used as an integer
BITs are used for Inverse operations, while boolean values are not used for logical operations.
Except ^, is, and in, other operations can be applied to the Variant type.
• No matter what the types of x and y are, the results of x/y are always extended. For other operators, there is only one
The operation number is a real number, and the result is an extension type. In addition, if one operation number is an Int64 type, the result is an Int64 type. Otherwise
The result is an integer. If an operation number is a subinterface of an integer, it is treated as an integer.
• The value of x div y is an integer, that is, the value of x/y is obtained, and the nearest integer is obtained in the direction of 0.
• Mod operation returns the remainder of the number after integer division. In other words, x mod y = x-(x div y) * y.
Boolean operators not, and, or, and xor act on the number of Boolean operations and return a Boolean value.
Use the $ B compiler to control the computation mode. The default status is {$ B-}, which adopts partial computation. Complete partial Calculation
Use the {$ B +} sign in the code. You can also select Complete Boolean In the Compiler Options dialog box.
Evaluation option. Full calculation is used throughout the project.
<Leo> // partially calculate equals short-circuit computation in C ++/C #
If any number of operations is of the variant type, the compiler always performs full calculation (even in the {$ B-} State)
Logical (bitwise) operators (bit Logical operator): not and or xor shl shr
• The return type and operation count of bitwise inverse (not) operations are the same;
• If and, or are all integer types, its return type is a predefined (built-in) Integer type that contains all possible values of the number and has the smallest range; • x shl y and x shr y shift the value of x to the left or right, which is equivalent to x multiplication or division by 2 ^ y (the power of y in 2 ), returns the same type as x. For example, if N is 01101 (13 in decimal format), then N shl 1 returns 11010 (26 in decimal format ). Note that the value of y is interpreted as a modulo operation on the type (number of digits) of x. For example, if x is an integer, x shl 40 is interpreted as x shl 8, because the integer size is 32 bits (4 bytes), 40 mod 32 equals 8.
Relational operators =, <>, <,>, <=, and> = can both operate on strings and use operators to connect two strings.
• The number of operators can be a string, packed string (packed arrays of type Char), or character. However, if one of the operations is
It is a wide character (WideChar) type, and the number of other operations must be a long string.
• The return result of the + operator is compatible with any string type. However, if the number of operations is a short string or character, and their combination length is greater than 255
, The first 255 characters are returned.
Relational operators <,>, <=, and> = can operate on the PChar type. Other operators: +-add or subtract the pointer ^ = <>
Equal to not equal
For the Pointer type, type conversion must be performed before dereference.
• If I is an integer and P is a character pointer, P + I adds the address of P to I, that is, a pointer to the end of P.
Pointer at the I character (expression I + P is equivalent to P + I); P? I is to subtract I from the P address, that is, a point to P
The pointer at the first I character.
• If both P and Q are character pointers, then P? Q calculates the difference between the P address (high address) and Q address (low address), that is
Returns an integer that represents the number of characters between P and Q. P + Q is meaningless.
Set operators (Set operators ):
+ Union-difference set * intersection <= less than or equal to (subset)> = greater than or equal to (superset) = equal to <> not equal to in member relationship
The following rules apply to + ,? And * operators:
• When and only when the ordinal number (a value in the basic set type) O belongs to the set X or the set Y (or both X and Y,
O belongs to X + Y. if and only when O belongs to X but not Y, O belongs to X? Y; if and only if O belongs to both X and Y
O belongs to X * Y.
• + ,? And * The calculation result belongs to the set type set of A. B. Here, A is the minimum ordinal number in the result, and B is
Maximum ordinal number.
The following rules apply to the <=, >=, =, <>, and in operators:
• X <= Y is true only when every member of X (SET) is a member of Y (SET). Z> = W is equivalent
W <= Z; U = V is true only when U (SET) and V (SET) share the same members. Otherwise, U <> V
True;
• For ordinal O and set S, O in S is true only when O is a member of S.
• Apart from the comparison of real numbers and integers, the two calculation numbers must be compatible;
• The character string is compared based on the order of each character in the extended ASCII character set. The character type is treated as the length
A string of 1;
• To compare two packed strings, they must have the same number of elements; a packed string with n elements
When compared with a string, it is considered as a string with a length of n;
• The <,>, <=, and> = operators can only be used when both PChar pointers point to the same character array.
For them;
• Operators = and <> can use the class or class reference type as the number of operations. When used for the class type, the calculation rules of = and <> and
The pointer is the same. Only when C and D point to the same instance object, C = D is true; otherwise, C <> D is true.
If C and D indicate the same class, C = D is true. Otherwise, C <> D is true.
The as and is operators use classes and objects (instances) as operation numbers, and the as operator is also used for interface types.
@ Operator returns the address of a variable, function, process, or method. That is to say, @ operator constructs
Pointer.
• If X is a variable, @ X returns the address of X (there are special rules when X is a process-type variable. For more information, see
Statement and the process type in the expression ). If the default compiler indicator {$ T ?} At the function, the @ X type is
Pointer (Universal Pointer); In the {$ T +} state, the @ X type is ^ T, where T is the X type;
• If F is a routine (a function or process), @ F returns the entry point of F, and the type of @ F is always Pointer;
• When @ acts on the class method, you must use the class name to limit the method name. For example
@ TMyClass. DoSomething
It points to the DoSomething method of TMyClass.
Set constructors)
[5, 6, 7, 8]
[5 .. 8]
[Red, green, MyColor]
[1, 5, 10 .. K mod 12, 23]
['A'... 'Z', 'A'... 'Z', Chr (Digit + 48)]
Set constructor [] indicates an empty set
Strings, arrays, array attributes, and pointers to strings or arrays can be indexed. For example: FileName [21]
The syntax for force type conversion is
TypeIdentifier (expression)
If the expression is a variable, the result is called variable typecast (variable conversion); otherwise, the result is a value typecast (value conversion ). Although
However, they have the same syntax, but they have different conversion rules.
In value conversion, the type specifiers and conversion expressions must be of an ordered type or pointer type. Examples of value conversion include:
Integer ('A ')
Char (48)
Boolean (0)
Color (2)
Longint (@ Buffer)
The Declaration syntax and position depend on the type of the identifier to be defined. Generally, a statement can only appear at the beginning of a block,
And the start of the unit interface or implementation part (after the uses clause ).
The Hint indicates that platform, deprecated, and library can be attached after any declaration. When declaring a process or function
Use a semicolon to separate the hint and other parts of the statement. For example:
Procedure someoldroutine; stdcall; deprecated;
VaR versionnumber: real library;
Type apperror = Class (exception)
...
End platform;
When the source code is compiled in the {$ hints on} {$ warnings on} status
An appropriate prompt or warning will be generated. Use platform to mark an entry and a specific operating system (such as windows and
Linux); deprecated indicates that the entry has been discarded or supported only for backward compatibility; library indicates that the entry depends on
A specific library or component framework (such as VCL or clx ).
The format of the value assignment statement is as follows:
Variable: = expression
Here, variable is any variable reference, including variable, variable type conversion, unreferenced pointer, or a group of structure variables.
Expression is a value-assignment-compatible expression. (In the function block, variable can be replaced by the function name. For more information, see procedures.
And functions.
When you enable the extended syntax ({$ x +}), you can call a function in the same way as the call procedure. When you call a function in this way, its return value is ignored.
Goto label
Label: Statement
Label label;
Label label1,..., labeln;
• Compound or with statements simply execute a series of statements;
• A Condition Statement, that is, an if or case statement, can execute a maximum of one branch according to the specified criteria;
• Loop statements, including repeat, while, and for loops, repeatedly execute a series of statements;
• A set of special statements, including the raise, try... try t, and try... finally structures, used to create and handle exceptions.
The syntax of the with statement is
With obj do statement
Or
With obj1,..., objn do statement
The if statement has two forms: if... then and if... then... else.
For example,
If J = 0 then
Exit
Else
Result: = I/J;
If J <> 0 then
Begin
Result: = I/J;
Count: = Count + 1;
End
Else if Count = Last then
Done: = True
Else
Exit;
Case Statements (Case statement ):
Case selectorExpression
CaseList1: statement1;
...
CaseListn: statementn;
Else
Statements;
End
Case I
1. 5: Caption: = 'low ';
6. 9: Caption: = 'high ';
0, 10 .. 99: Caption: = 'out of range ';
Else
Caption: = '';
End;
SelectorExpression is any sorted expression (the string is invalid), which is the same as C ++.
. Object Pascal has three types of loops: repeat statements, while statements, and for statements.
Use the Break and Continue processes to control the repeat, while, or for statements.
The repeat statement syntax is
Repeat statement1;...; statementn; until expression
For example:
Repeat
Write ('enter a value (0 .. 9 ):');
Readln (I );
Until (I> = 0) and (I <= 9 );
The while statement syntax is
While expression do statement
For example:
While I> 0 do
Begin
If Odd (I) then Z: = Z * X;
I: = I div 2;
X: = Sqr (X );
End;
The syntax of the for statement is
For counter: = initialvalue to finalvalue do statement
Or
For counter: = initialvalue downto finalvalue do statement
For example: for C: = Red to Blue do Check (C );
A block contains a series of statements followed by a statement. All declarations must appear at the beginning of the block.
The format is
Declarations;
Begin
Statements;
End;
For example:
Function UpperCase (const S: string): string;
Var
Ch: Char;
L: Integer;
Source, Dest: PChar;
Begin
...
End;