Sunday, June 12, 2011

2.Data Type, Variables and Operators

2.Data Type Variables and Operators
2.1 Data Type
2.2 Constans
2.3 Variabels
2.4 Operators



2.1 Data Type
Borland offers several types of data. we have to learn it, so it can be used properly and efficiently.there are several considerations to determine the Data type that we will use in the program.
  • memory usage and data ranges

there are differences in the allocation of memory for one type of data with other data types. The best course uses data types according to our needs. example if we procces the data having ranges (0-100 )without decimals, then we used data type : Byte.(it is needed 1 Byte), compared if we use data type : word (2 byte ) or Integer (4 byte).but of course, if we processing the data over data type Byte( >100). we must not use data type :Byte.


  • accuracy of calculation

although the memory savings is needed but we must having accuracy in calculation.so we must use the data type that having accuration in calculate.

there are data Type used in Borland
  • 2.1.1 Integer
  • Integer used to specify the number with no decimal. there are integer tipe with range in memory used
    Tipe Ranges Byte
    Byte 0-255 1
    Word 0-65535 2
    ShortInt -128-127 1
    SmallInt -32768 - 32767 2
    Integer -2147483648 - 147483647 4
    Cardinal 0 - 2147483648 4
    LongInt 2147483648 - 147483647 4
  • 2.1.2
  • Used to declaretype of data that contains decimals
    Type Ranges Byte
    Real48 2.9 x 10-39 s.d 1.7 x 1038 6
    Single 1.5 x 10-45 s.d 3.4 x 1038 4
    Double 5.0 x 10-324 s.d 1.7 x 10308 8
    Extended 3.6 x 10-4951 s.d 1.1 x 104932 10
    Comp -263+1 s.d 263-1 8
    Currency -922337203685477.5808 s.d 922337203685477.5807 8
    real48 is used to maintain compatibility with previous versions of Delphi, extendedtype have a better accuracy but less in compatibility, currency type is best used to store fixed data are large, making it suitable to accommodate the value of currency and better in accuration
  • 2.1.3 Boolean
  • it is used to declare logic data, thats TRUE and FALSE borland delphi have 4 boolean type :
    Type Byte
    Boolean 1
    ByteBool 1
    WordBool 2
    LongBool 4
  • 2.1.4 Character
  • used to declare character 1 letter.borland have 3 Character Type:
    Type Byte Fields
    Char 1 1 ANSI Character
    AnsiChar 1 1 ANSI Character
    WideChar 2 1 Unicode Character
  • 2.1.5 String
  • Used to declare more character example ; name, adress, code etc. borland have 3 string type:
    Type Byte Max Fields
    ShortString 2 s.d 256 256 Character
    AnsiString 4 s.d 2 GB 231Character
    WideString 4 s.d 2 GB 230 Character
    ShortString its prevent the compability with other version of borland,AnsiString used to store ANSI Character, wideString used to store Unicode Character.
  • 2.1.6 Array
  • Array is a single variable that can be used to store a set of similar data. to make differrent path array using element number in the right of array name : view the example: var day:array[1..7] of AnsiString; begin day[1]:='Sunday'; day[2]:='Monday'; . . . . . . edit1.text:=day[1];
  • 2.1.7 Record
  • record data type used to store a set of data that may be different types, but interrelated. sample data using record Type ex: to save item data that contains; item code, item name and unit price. note the following program snippet :

    type recitem=record code : String[6]; name : String [30]; Unitprice : Single; end; var itemm : recitem; begin itemm.code :='ns.001'; itemm.name :='naruto sipudden'; itemm.unitprice :=15000;
  • 2.1.8 Enumeration and SubRange type
  • expressed sequence data with similar type. enumerate declarations exampes : type> color = (red, blue, green, yellow, orange, black, white ); var paintcolor : color; subrange declaration examples type mycolor = blue..orange; uppercase='A'..'Z'; value =0..100; var paintcolor=mycolor; testscores=value; finalvalue=uppercase;

No comments:

Post a Comment