variable is a place in the computer memory that is named (as an identifier) and allocated to accommodate data. the difference between variable and const are :
- const used when compiling program, and variables it is used when the program RUN
- const can not change when program run, and variables can changed while program run.
each variable have a name called identifier. it recommended when you making variable name you must accordance with the data contain and easy to remember.
some rules that apply when making a variable :
- must start with character( letter) or underscore
- unique(not same with other variables)in same scope
- note the length character , just 63 character can be read as variable (64 character thereafter will be ignored)
- some characters that should not be used : operator(+, -, *, /, <, >,:, ;, , , etc)
2.3.2 variables scope
Variables scope is area variable used.usually associated with age (life time) variable. several variables are known throughout the program and used while the program run. some variable known in procedure and function and it just used when the procedure and function start.
generally, a variable will be recognized in the scope where variable declared. as samples : if you declaring variable on function, then the scope of variable just start begin declaration line untill end of funtion. including the function or procedure called by the function. whereas if variable declared on interface in the unit, then the scopes of variable start from declaration line untill end of unit. including other unit called by the unit.
global variable is a larges variable scope.
local variableis a smallest variable scope.
unit Unit1;
interface
uses
windows, Message, SysUtils, Classes, Gaphics, Controls,
Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(sender : TObject);
procedure FormClick(sender : TObject);
private
{private declarations}
public
{public declarations}
end;
var
Form1 : TForm;
A : Single;
implemetation
{SR *.DFM}
procedure FormCreate(sender : TObject);
begin
A:=5; //this is global varaible
end;
procedure FormClick(sender : TObject);
var A: single
begin
A:=10;//this is local variable;
end;
end.
No comments:
Post a Comment