Sunday 11 April 2010

Delphi Tutorial # 4

Identifier and Data Type

In this tutorial, we’re going to learn about Pascal Object - that serves as a basic for Delphi – such as data type, constant and variable. And you’ll be able to declare variables in a program and use operators in a statement.

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
andarrayasasm
begincaseclassconst
constructordestructordispinterfacediv
dodowntoelseend
exceptexportsfilefinalization
finallyforfunctiongoto
ifimplementationininherited
initializationinlineinterfaceis
labellibrarymodnil
notobjectofor
outpackedprocedureprogram
propertyraiserecordrepeat
resourcestringsetshlshr
stringthenthreadvarto
trytypeunituntil
usedvarwhilewith
xorprivateprotectedpublic
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

TypeRangeMemory Size
Byte0 to 2551 byte
Word0 to 655352 byte
ShortInt-128 to 1271 byte
SmallInt-32768 to 327672 byte
Integer-2147483648 to 21474836474 byte
Cardinal0 to 21474836474 byte
LongInt-2147483648 to 21474836474 byte

Char

TypeMemory SizeSaved Character
ANSIChar1 bytean ANSI Char
WideChar2 bytean Unicode Char
Char1 bytelike an ANSIChar

Boolean

TypeRangeMemory Size
Booleanone byte1 byte
ByteBoolone byte1 byte
Boolone word2 byte
WordBoolone word2 byte
LongBooldouble4 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.

Go to Previous Tutorial or Next Tutorial

3 comments:

  1. tutorial yang sangat memikat, walaupun pakde harus meraba raba , karena pakde buta sama sekali tentang artikel ini

    ReplyDelete
  2. Thank you pakde for following my articles

    ReplyDelete
  3. Thanks for sharing about Delphi development . in a Tutorial basis. Excellent one.

    ReplyDelete

These links are part of a pay per click advertising program called Infolinks. Infolinks is an In Text advertising service; they take my text and create links within it. If you hover your mouse over these double underlined links, you will see a small dialog box containing an advertisement related to the text. You can choose to move the mouse away and go on with your browsing, or to click on the box and visit the relevant ad. Click here to learn more about Infolinks Double Underline Link Ads.