Quick start manual
Syntactic elements
4-23
Declarations and statements
This is equivalent to
if OrderDate.Month = 12 then
begin
OrderDate.Month := 1;
OrderDate.Year := OrderDate.Year + 1;
end
else
OrderDate.Month := OrderDate.Month + 1;
If the interpretation of obj involves indexing arrays or dereferencing pointers, these
actions are performed once, before statement is executed. This makes with statements
efficient as well as concise. It also means that assignments to a variable within
statement cannot affect the interpretation of obj during the current execution of the
with statement.
Each variable reference or method name in a with statement is interpreted, if
possible, as a member of the specified object or record. If there is another variable or
method of the same name that you want to access from the with statement, you need
to prepend it with a qualifier, as in the following example.
with OrderDate do
begin
Year := Unit1.Year
ƒ
end;
When multiple objects or records appear after with, the entire statement is treated
like a series of nested with statements. Thus
with obj
1
, obj
2
, ..., obj
n
do statement
is equivalent to
with obj
1
do
with obj
2
do
ƒ
with obj
n
do
statement
In this case, each variable reference or method name in statement is interpreted, if
possible, as a member of obj
n
; otherwise it is interpreted, if possible, as a member of
obj
n–1
; and so forth. The same rule applies to interpreting the objs themselves, so that,
for instance, if obj
n
is a member of both obj
1
and obj
2
, it is interpreted as obj
2
.obj
n
.
If statements
There are two forms of if statement: if...then and the if...then...else. The syntax of an
if...then statement is
if expression then statement
where expression returns a Boolean value. If expression is True, then statement is
executed; otherwise it is not. For example,
if J <> 0 then Result := I/J;