I.T. Discussion Community!
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesDelphiStatements  Print This     

Cross Ref > Statements

By Mike Prestwood

Delphi versus Access VBA: A side by side comparison between Delphi and Access VBA.


Common statements such as if statements, loops, etc.

Exception Trapping

[Other Languages] 

Languages Focus

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

Delphi:   try..except, try..finally

Use a try..except..end block to trap and process errors.

Delphi also offers a try...finally where code will execute in the finally section no matter what. It's common to put a try..except inside a try..finally.

Syntax Example:
y : Double;
y := 0;
y := (1/y);
ShowMessage('You cannot divide by zero.');
[Not specified yet. Coming...]

If Statement

[Other Languages] 
Delphi:   If..Else If..Else

Notice in the more complete example that the semicolon for the begin..end block after end is not included. That tells the compiler something else is coming (the statement is not finished). Also note the semicolon is missing right before the final "else" statement.

Note: The following example uses floating point literals. In Delphi, to specify a fractional floating point literal between 1 and -1, you preceed the decimal with a 0; otherwise, you will get a compiler error (i.e. .1 + .1 does not work).

Syntax Example:
if (0.1 + 0.1 + 0.1) = 0.3 then
  ShowMessage('Not correct');
//Complete example:
if x = true then
  ShowMessage('x is true');
Else If y = 'Mike' Then 
  ShowMessage('hello mike')
  ShowMessage('last option');
Access VBA:   If..ElseIf..Else..End If

The End If is optional if you put your code on a single line.

Syntax Example:
//Single line example.
If X = True Then MsgBox "hello" 
//Complete example. 
If X = True Then
'>>>do something.
ElseIf Y = "ABC" Then
'>>>do something.
'>>>do something.
End If

Follow PrestwoodBoards on: 

©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech