ローカル変数とグローバル変数の違いを確認する
プロシージャを作成すると、グローバル変数やローカル変数など、複数の変数をプロシージャで使用できます。 ローカル変数は定義されているプロシージャの中でのみアクセスできるため、使用できる範囲は現在使用しているプロシージャに限定されます。
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;
グローバル変数は、定義されているオブジェクト内のどこからでもアクセスできます。 オブジェクトの外部からはアクセスできません。 グローバル プロシージャのみが他のオブジェクトによってアクセスできます。
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;