Expressions & Statements
var
l : Boolean;
g : Boolean;
begin
l := 10 > 3; { boolean test as true }
if l then
Memo1.Lines.Add('The Result is True.....')
else
Memo1.Lines.Add('The Result is False.....');
{ w/ logical and operator }
g := (10 > 3) and (-1 > 0);
end;
{ Labels and GOTO statements, for jump'n to other }
{ part of the program body }
procedure TStatements.GotoButtonClick (Sender : TObject );
label Starter, Ender;
begin
MessageDlg('Before the Starter label',mtInformation,[mbOk],0);
Starter:
MessageDlg('After the Starter label, before the goto',
mtInformation,[mbOk],0);
goto Ender; { jump here }
MessageDlg('After the goto Statement',
mtInformation,[mbOk],0);
Ender:
MessageDlg('After the Ender Label',
mtInformation,[mbOk],0);
end;
{ sample for enum statements, see under type below }
procedure TStatements.CaseButtonCLick(Sender : TObject);
type
TDaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,
Thursday, Friday, Saturday);
var
Today : TDaysOfWeek;
begin
case Today of
Sunday : MealOfTheDay := BroiledChicken;
Monday : MealOfTheDay := Humburger;
Tuesday : MealOfTheDay := PorkRoast;
Wednesday: MealOfTheDay := Linguini;
Thursday : MealOfTheDay := PattyMelt;
Friday : MealOfTheDay := Veal;
else MealOfTheDay := BLT;
end;
end;
|