Quick start manual

4-22
Delphi Language Guide
Declarations and statements
Compound statements are essential in contexts where Delphi syntax requires a single
statement. In addition to program, function, and procedure blocks, they occur within
other structured statements, such as conditionals or loops. For example:
begin
I := SomeConstant;
while I > 0 do
begin
ƒ
I := I - 1;
end;
end;
You can write a compound statement that contains only a single constituent
statement; like parentheses in a complex term, begin and end sometimes serve to
disambiguate and to improve readability. You can also use an empty compound
statement to create a block that does nothing:
begin
end;
With statements
A with statement is a shorthand for referencing the fields of a record or the fields,
properties, and methods of an object. The syntax of a with statement is
with obj do statement
or
with obj
1
, ..., obj
n
do statement
where obj is an expression yielding a reference to a record, object instance, class
instance, interface or class type (metaclass) instance, and statement is any simple or
structured statement. Within statement, you can refer to fields, properties, and
methods of obj using their identifiers alone—without qualifiers.
For example, given the declarations
type TDate = record
Day: Integer;
Month: Integer;
Year: Integer;
end;
var OrderDate: TDate;
you could write the following with statement.
with OrderDate do
if Month = 12 then
begin
Month := 1;
Year := Year + 1;
end
else
Month := Month + 1;