Identifier and Data Type
In this tutorial, we’re going to learn about Pascal Object - that serves as a basic for
Identifier
Identifier is used to declare constant, variable, unit, function, procedure etc. An identifier can be preceded by an underscore ( _ ), next character can be number, character string or underscore. The length of an identifier can be more than 255 characters, but only 255 first characters will be considered as an identifier. The rest characters will be ignored. Capital letter or small letter will be considered the same. And an identifier has to be non reserved word :
RESERVED WORD | |||
---|---|---|---|
and | array | as | asm |
begin | case | class | const |
constructor | destructor | dispinterface | div |
do | downto | else | end |
except | exports | file | finalization |
finally | for | function | goto |
if | implementation | in | inherited |
initialization | inline | interface | is |
label | library | mod | nil |
not | object | of | or |
out | packed | procedure | program |
property | raise | record | repeat |
resourcestring | set | shl | shr |
string | then | threadvar | to |
try | type | unit | until |
used | var | while | with |
xor | private | protected | public |
published automated |
Some examples of identifier are sum, salary, price, year etc. SALARY, Salary and salary are the same, because capital letter or small letter are considered the same.
Simple Data Type
Now we’ll learn some of data types in Pascal Object. Some of them categorize in simple data type. There are two simple data type : ordinal (integer, char, Boolean, string etc) and real.
Integer
Type | Range | Memory Size |
---|---|---|
Byte | 0 to 255 | 1 byte |
Word | 0 to 65535 | 2 byte |
ShortInt | -128 to 127 | 1 byte |
SmallInt | -32768 to 32767 | 2 byte |
Integer | -2147483648 to 2147483647 | 4 byte |
Cardinal | 0 to 2147483647 | 4 byte |
LongInt | -2147483648 to 2147483647 | 4 byte |
Char
Type | Memory Size | Saved Character |
---|---|---|
ANSIChar | 1 byte | an ANSI Char |
WideChar | 2 byte | an Unicode Char |
Char | 1 byte | like an ANSIChar |
Boolean
Type | Range | Memory Size |
---|---|---|
Boolean | one byte | 1 byte |
ByteBool | one byte | 1 byte |
Bool | one word | 2 byte |
WordBool | one word | 2 byte |
LongBool | double | 4 byte |
Real
String
Constant and Variable
Constant is a fixed value that is used in a program. To define a constant in a program, we use a reserved word const. Example :
const
discount = 0.1
or
const
discount : real = 0.1
discount is a constant which value is 0.1
But in a program, a value is not always fixed but it can be constantly changing. To handle this, we need variables. A variable can contain a value, and the value can be changed anytime. Before we can use a variable, it has to be declared first. Use reserved word var to declare a variable :
Var
Age : byte;
Address : string;
Salary : currency;
Age is a byte variable, its value can be 0 to 255. Address is a string variable. And Salary is a currency variable.
tutorial yang sangat memikat, walaupun pakde harus meraba raba , karena pakde buta sama sekali tentang artikel ini
ReplyDeleteThank you pakde for following my articles
ReplyDeleteThanks for sharing about Delphi development . in a Tutorial basis. Excellent one.
ReplyDelete