Free Pascal Lazarus Program Tutorial 11 - Preventing Crashes With Val


The crash happens when the computer is expecting an integer or floating-point number and gets a non-number character. This causes the program to crash and / or produce error messages. The solution is to prevent non-numbers from being placed into integer or floating point variables. This can be done by using val. Val converts strings to numbers.

Syntax
Val(StringVar, NumberVar, ErrorVar);
If Error = 0, then the conversion was successful.
If Error is something other than 0, then we know there is a problem.

Code Download
FPProgT11.zip