The Free Pascal language contains several readily available types. Try the above examples in the Lazarus IDE and see how it reacts to incorrect types. We could fix the above example by converting the integer result of A + B like so:Ĭ := IntToStr(A + B) // OK, we can explicitly convert A + B to a string If we want to work on types correctly we need to explicitly convert them if the type rules say we are violating the rules.
The strict type checking helps us by finding problems in our source code ahead of time. It makes sure that we are using our variables in the correct manner before we can successfully compile our programs.
This is what the strict type system does.
The error is telling us that two integers add up to another integer, and not a string. What do you suppose would happen?īoth the IDE and the compiler will generate an error. Now suppose we were to change the type of C to a string. This is valid syntax because the Integer type has defined rules allowing the add operator + to work upon two integer types. Notice in line 7 we add integers A and B. WriteLn('Enter two numbers and I will add them together') Ĭ := A + B // OK, the type system says we can add two Integers For example the type rules allow us to add two integers together like so: The strict typing rules in the compiler determine how these types can be used. So far we've used the Integer and string types. These definitions enforce the rules used when working with variables which determine how your variables can be used. In terms of programming languages, types are strict definitions associated with variables and constants which both the IDE and compiler can see. We demonstrate how they work.įree Pascal is a strictly typed language.
We install the terminal and todo list enhancements, rebuilding the IDE. We also show how the IDE includes its source code and can be rebuilt. We go through some options to demonstrating how they work. We go through some of the menus and options to familiarize the student with some of the basic functionality in the IDE. In this section we take a closer look at the Lazarus IDE. Day 3 introduces the concept of types.īelow are the topics and course materials we are learning today. That is perhaps a little simpler, but not much.This is the day 3 page for computer programming course 101, an introductions to computer programming. It splits the string, using a given delimiter (here ' ') into a dynamic array. If your version of FreePascal has a unit StrUtils with a SplitString function in it, you can use that instead of a TStringList. The only way to get these items is to read the entire string and then to parse it (split it). You should probably add error checking for the case you get bad input, and perhaps use TryStrToInt instead of StrToInt, but I'll leave that as an exercise.Īs said, in your question, you are trying to read Chars, which causes problems, because for instance a space and a tab are also a Chars, so the space delimiters don't work as you expected here. Split s into four entries in the string listĪ := sl // first string item, convert to charī := StrToInt(sl) // second string item, convert to integerĬ := sl // third string item, convert to charĭ := StrToInt(sl) // fourth string item, convert to integer Writeln('Enter a char, a number, a char and a number again, separated by spaces:') As commented, and as explained, your code won't work as-is.Īssuming you have a FreePascal version that knows the TStringList type in unit Classes (I guess all recent ones do), you can do the following: uses