Common Error Checklists for Smart Pascal
unit Unit1; interface uses System.Types, SmartCL.System, SmartCL.Components, SmartCL.Application, SmartCL.Game, SmartCL.GameApp, SmartCL.Graphics, System.Colors; type TCanvasProject = class(TW3CustomGameApplication) protected procedure ApplicationStarting; override; procedure ApplicationClosing; override; procedure PaintView(Canvas: TW3Canvas); override; end; var strAge: String; Age: Integer; implementation procedure TCanvasProject.ApplicationStarting; begin inherited; strAge := Prompt('How old are you? Please enter an integer.'); Age := StrToInt(strAge); GameView.Delay := 1000; GameView.StartSession(True); end; procedure TCanvasProject.ApplicationClosing; begin GameView.EndSession; inherited; end; procedure TCanvasProject.PaintView(Canvas: TW3Canvas); begin Canvas.FillStyle := 'rgb(0, 0, 99)'; Canvas.FillRectF(0, 0, GameView.Width, GameView.Height); Canvas.Font := '10pt verdana'; Canvas.FillStyle := 'rgb(255, 255, 255)'; Canvas.FillText('Age next year: ' + IntToStr(Age + 1), 10, 20); end; end.
You should, of course, validate the user input.
var i: Float = 0; while(i <> 10) do i += 0.2;
Common syntax errors
Do not be discouraged if your first Smart Pascal programs generate many error messages. Often there are cascading errors, in which a single mistake such as a misspelled identifier in a variable declaration gives rise to several error messages. The following table shows extracts from common error messages.
|Description of error||Typical message content||Comment|
|Misspelled identifier||Unknown name "Poits"||Spelling of identifier must be consistent|
|Previous statement not separated by semicolon||"ENSURE" or "END" expected||Error indicated on the line following the missing semicolon
Tip: The error message is not always on the line with the error, so remember to look at adjacent nearby lines as well.
|Semicolon immediately before else||"ENSURE" or "END" expected||The if … then … else is one statement and should not have a semicolon immediately before else.|
|Use of = instead of := for simple assignment e.g.
Total = 0;
|"ENSURE" or "END" expected||Common error when converting from pseudo-code|
|Use of = instead of := for assigning control variable in for
for Count = 1 to 5 ...
|Use of := instead of
= in test of equality e.g.
if Total := 10 then ...
|Identifier of variable contains space e.g.
var my num : real;
|Colon ":" expected|
|Identifier of variable begins with digit e.g.
var 2ndPlace : string;
|Number, point or exponent expected (found "n")||Identifier must begin with letter or underscore|
|Identifier of procedure begins with digit e.g.
|Number, point or exponent expected (found "T")||Identifier must begin with letter or underscore|
|String literal not enclosed by quotes e.g.
Forename := Joe;
|Unknown name "Joe"|
|Use of round brackets to enclose array index e.g. MyArray(63)||Not a method||Use square brackets to enclose array index.|
|Real number starts with decimal point e.g.
MyReal := .34;
|Expression expected||Include the leading 0 e.g.
MyReal := 0.34;
Required unit (e.g. System.Colors) not included in uses section:
Canvas.FillStyle := ColorToWebStr(clForestGreen);
|Unknown name "ColorToWebStr"|
|Argument type does not match parameter type when calling a subroutine||Syntax Error: Argument 0 expects type "Integer" instead of "String"|
|Expression operated on by logical operators not enclosed in brackets. e.g.
until Count = MAX or Found;
until (Count = MAX) or Found;
|Array bounds error e.g.
var MyArray: array[0..1] of integer; MyArray := 3;
|Upper bound exceeded! Index 2||Array bounds check|