Identify differences between local and global variables
When you create a procedure, your procedure can work on many variables, including global and local variables. Local variables can only be accessed in the procedure where they're defined, so the scope is limited to the current procedure that you're working on.
procedure MyFunction()
var
myInt: Integer;
begin
myInt := 5; // The variable myInt is only available in this function
end;
procedure MyFunction2()
begin
myInt := 6; // The variable myInt is not in the scope of MyFunction2
end;
Global variables can be accessed from everywhere in the object where they're defined. They can't be accessed outside the object. Only global procedures can be accessed by other objects.
var
myInt2: Integer
procedure MyFunction()
var
myInt: Integer;
begin
myInt := 5; // The variable myInt is only available in this function
myInt2 := 10; // myInt2 is accessible everywhere in the object
end;
procedure MyFunction2()
begin
myInt := 6; // The variable myInt is not in the scope of MyFunction2
myInt2 := 11; // myInt2 is accessible everywhere in the object
end;