You need to map each begin to end at the same level, e.g.
if Condition then begin DoSomething; end else begin DoADifferentThing; end;
You can reduce the number of lines used without affecting the placement if you want. (It might be easier if you get used to the syntax for the first time.)
if Condition then begin DoSomething end else begin DoADifferentThing; end;
If you execute a single statement, begin..end are optional. Note that the first condition does not contain a final one ; , since you have not finished the statement:
if Condition then DoSomething else DoADifferentThing;
The semicolon is optional for the last statement in the block (although I usually include it even when it is optional, to avoid future problems when adding a line and forget to update the previous line at the same time).
if Condition then begin DoSomething; // Semicolon required here DoSomethingElse; // Semicolon optional here end; // Semicolon required here unless the // next line is another 'end'.
You can combine one and several blocks of statements:
if Condition then begin DoSomething; DoSomethingElse; end else DoADifferentThing; if Condition then DoSomething else begin DoADifferentThing; DoAnotherDifferentThing; end;
Proper use of your code:
procedure InitializeWizard; begin Log('Initialize Wizard'); if IsAdminLoggedOn then begin SetupUserGroup(); SomeOtherProcedure(); end else begin Log('User is not an administrator.'); msgbox('The current user is not administrator.', mbInformation, MB_OK); end; end;
Ken white
source share