So far we have considered only constant expressions. Constant expressions are expressions that can be fully evaluated at compile time (before the program runs). If all expressions were constant expressions then there would not be any need for a program in the first place. Variables are named symbols that can store data. For example, X, SomeVar, and Var1 are all identifiers that could be used to declare a variable. We say declare here because in Object Pascal we must declare a variable and in most cases its type before we use it. This requirement exists because Object Pascal, like C and C++, is a strongly-typed language. This means that the compiler knows the type of data that a variable can contain at compile-time. It also prevents programmer errors such as assigning a string to a variable that was meant to contain an integer.  There are several predefined constants and types in Object Pascal which are summarized in the table below. From our previous discussions of expressions you can probably guess what each type means by its name.
Identifier
Ord
Kind
Purpose
Boolean
Yes
Predefined Truth Type
Requires that a variable or constant holds 1 of 2 logical values: true or false
True
Yes
Predefined Boolean Constant
Represents true
False
Yes
Predefined Boolean Constant
Represents false
Integer
Yes
Predefined Numeric Type
Requires that a variable or constant holds a number without a decimal
Real
No
Predefined Numeric Type
Requires that a variable or constant holds a valid number that may or may not have a decimal
Char
Yes
Predefined Character Type
Requires that a variable or constant holds a single character
String
No
Predefined String Type
Requires that a variable or constant holds a character or string of characters
Also specified in this table is whether or not a type is ordinal. If a type is ordinal it means that the values it can contain have a specific order and that each unique value of an ordinal type also has a unique predecessor and successor (except the first and last values of course). This may sound complicated, but it is actually quite simple if you think about it. An integer is an ordinal type. We know this because if you choose any integer, let's say 5 for now, you know what number comes before it and what number comes after it immediately. A real is not an ordinal because even if we know 4.0 comes before 5.0, any infinite number of reals could be between them including 4.1, 4.35, 4.999, etc. A string is not an ordinal type because given the string 'somestring' we cannot say simply by looking at it alone and nothing else what string must come before it and what must come after it (this is because there is an infinite number of strings that could theoretically come before or after it). On the other hand, a character is ordinal. This is because if we have a single character like 'c' we know that 'b' must come before it and 'd' must come after it. We will not cover all the implications of being an ordinal type here, but you should know that many of the other statements and expressions we will discuss can use only ordinal types.

In order to understand how variables and types work, modify the Workspace program to contain the following lines:
{$APPTYPE CONSOLE}
program Workspace;
var
  X,Y : Integer;
begin
  Writeln('This program will sum two integers.');
  Write('Type the first integer and press enter: ');
  Readln(X);
  Write('Type the second integer and press enter: ');
  Readln(Y);
  Writeln('The sum of ',X,' and ',Y,' is ',X+Y);
  Readln;
end.
The var reserved word tells the compiler that you are about to declare variables. You can declare as many variables after var as you need. Now run the program with the values 2 and 5. The Write function is slightly different than Writeln in that it does not force the program to go to the next line. Also, note the new use of the Readln function with a single argument. Although previously we have used Readln only to wait for the enter key to be pressed, Readln has an optional argument that allows a value to be read into a variable once the enter key is pressed. The ability of a subroutine to have optional arguments or arguments of different types is known as overloading. Finally, the last Writeln statement has 6 arguments passed to it instead of only 1. This is a feature completely unique to Readln, Write, and Writeln. The following are the definition of these functions in the Object Pascal documentation:
Readln(V1 [, V2, ... , Vn ]);

Writeln(V1 [, V2, ... , Vn ] );

Write(V1 [, V2, ... , Vn ] );
The square brackets stand for optional arguments. Although many functions in Object Pascal have optional arguments, none allow an unlimited number of arguments like these three.

Run the program again but this time use 2.2 and 5. You will find that a runtime error occurs because 2.2 is a real and X was typed to an integer. You can recover from the error by pressing Ctrl+F9 in the editor and choosing to stop the debug process. The same would have happened if you had entered the string 'test' for X.
Excercise 2-8.
Write code to solve the following problems.
  1. Write a program that loads your name into a string variable and then replies "Hello, YourName!".
  2. Write a program that reads a dividend (number to be divided) and divisor (number that divides the dividend) into integer variables and returns a quotient in mixed fraction form (e.g. 7 divided by 3 equals 2 and 1/3). Hint: You should use "div" and "mod".
So far, we have used only Readln to load values into variables. More commonly we will use the assignment operator := to store a value in a variable:
{$APPTYPE CONSOLE}
program Workspace;
var
  X,Y : Integer;
begin
  X := 5; Y := 10;
  Writeln('The sum of ',X,' and ',Y,' is ',X+Y);
  Readln;
end.
An assignment is another example of a simple statement. So now we know that subroutine calls and assignments are two types of statements.

In addition to variables, you can also declare constant symbols if you know that the value of data will not change at any time in the program. For example, in the program above we could have declared the description string for the program as a constant using the "const" reserved word.
{$APPTYPE CONSOLE}
program Workspace;
const
  DescrString = 'This program will sum two integers.';
var
  X,Y : Integer;
begin
  Writeln(DescrString);
  Write('Type the first integer and press enter: ');
  Readln(X);
  Write('Type the second integer and press enter: ');
  Readln(Y);
  Writeln('The sum of ',X,' and ',Y,' is ',X+Y);
  Readln;
end.
It does not matter if the const or var section comes first and any number of const or var sections can exist in the program. Also, you will notice that DescrString is not explicitly typed. This is because the compiler can see that DescrString will always hold a string. It assigns the type implicitly. You could optionally define the type explicitly:
const
  DescrString : String = 'This program will sum two integers.';
Constants are automatically replaced at compile-time with their defined values. This helps reduce the amount of memory that an application has to allocate for the storage of variables. Although this might seem obvious, it is worth stating: Constants cannot be assigned to using the assignment operator or Readln since their values should never change.