Common Error Checklists for Smart Pascal
This page is a Smart Pascal version of our popular common error checklists for Lazarus and Delphi, where we provide an introduction to the different types of error. The checklist for logic errors applies equally well to Smart Pascal but the syntax error messages tabulated below are very different. With Smart Pascal the error situation is complicated by the fact that the output is JavaScript rather than machine code. The JavaScript, when translated by the browser, should not fail due to a syntax error because it has been generated by the Smart Pascal compiler rather than by an error-prone human. Runtime responses to erroneous situations may be very different in Pascal and JavaScript. Upon a failed attempt to convert a string to an integer, JavaScript returns NaN (Not a Number). The following Smart Pascal program outputs "Age next year: NaN" in response to the erroneous user input Fifteen. The equivalent Pascal program would crash.
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.
The following code translates to JavaScript that causes the browser to hang (because the value of i as stored by the computer is never exactly equal to 10):
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
loop e.g.
for Count = 1 to 5 ... |
":=" expected | |
Use of := instead of
= in test of equality e.g.
if Total := 10 then ... |
Boolean expected |
|
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.
procedure 5Times; |
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; |
Invalid Operands |
Should be: until (Count = MAX) or Found; |
Array bounds error e.g.var MyArray: array[0..1] of integer; MyArray[2] := 3; |
Upper bound exceeded! Index 2 | Array bounds check ![]() |