Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə76/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   72   73   74   75   76   77   78   79   ...   294
DelphiLanguageGuide

Generic integer types
62


Type
Range
Format
.NET Type Mapping
Integer
-2147483648..2147483647 signed 32-bit
Int32
Cardinal 0..4294967295
unsigned 32-bit UInt32
Fundamental integer types include Shortint, Smallint, Longint, Int64, Byte, Word, and Longword.
Fundamental integer types
Type
Range
Format
.NET Type Mapping
Shortint
-128..127
signed 8-bit
SByte
Smallint
-32768..32767
signed 16-bit
Int16
Longint
-2147483648..2147483647 signed 32-bit
Int32
Int64
-2^63..2^631
signed 64-bit
Int64
Byte
0..255
unsigned 8-bit
Byte
Word
0..65535
unsigned 16-bit UInt16
Longword 0..4294967295
unsigned 32-bit UInt32
In general, arithmetic operations on integers return a value of type Integer, which is equivalent to the 32-bit Longint.
Operations return a value of type Int64 only when performed on one or more Int64 operand. Hence the following
code produces incorrect results.
var
  I: Integer;
  J: Int64;
   ...
  I := High(Integer);
  J := I + 1;
To get an Int64 return value in this situation, cast 
I
 as Int64:
...
J := Int64(I) + 1;
For more information, see Arithmetic operators.
Note:
Some standard routines that take integer arguments truncate Int64 values to 32 bits. However, the 
High
,
Low

Succ

Pred

Inc

Dec

IntToStr
, and 
IntToHex
 routines fully support Int64 arguments. Also, the
Round

Trunc

StrToInt64
, and 
StrToInt64Def
 functions return Int64 values. A few routines cannot
take Int64 values at all.
When you increment the last value or decrement the first value of an integer type, the result wraps around the
beginning or end of the range. For example, the Shortint type has the range 128..127; hence, after execution of the
code
var I: Shortint;
  ...
  I := High(Shortint);
  I := I + 1;
63


the value of 
I
 is 128. If compiler range-checking is enabled, however, this code generates a runtime error.
Character Types
The fundamental character types are AnsiChar and WideChar. AnsiChar values are byte-sized (8-bit) characters
ordered according to the locale character set which is possibly multibyte. AnsiChar was originally modeled after the
ANSI character set (thus its name) but has now been broadened to refer to the current locale character set.
WideChar characters use more than one byte to represent every character. In the current implementations,
WideChar is word-sized (16-bit) characters ordered according to the Unicode character set (note that it could be
longer in future implementations). The first 256 Unicode characters correspond to the ANSI characters.
The generic character type is Char, which is equivalent to AnsiChar on Win32, and to Char on the .NET platform.
Because the implementation of Char is subject to change, it's a good idea to use the standard function 
SizeOf
rather than a hard-coded constant when writing programs that may need to handle characters of different sizes.
Note:
The WideChar type also maps to Char on the .NET platform.
A string constant of length 1, such as 'A', can denote a character value. The predefined function 
Chr
 returns the
character value for any integer in the range of AnsiChar or WideChar; for example, 
Chr(65)
 returns the letter A.
Character values, like integers, wrap around when decremented or incremented past the beginning or end of their
range (unless range-checking is enabled). For example, after execution of the code
var
  Letter: Char;
  I: Integer;
begin
  Letter := High(Letter);
  for I := 1 to 66 do
    Inc(Letter);
end;
Letter
 has the value A (ASCII 65).
Boolean Types
The four predefined Boolean types are Boolean, ByteBool, WordBool, and LongBool. Boolean is the preferred type.
The others exist to provide compatibility with other languages and operating system libraries.
A Boolean variable occupies one byte of memory, a ByteBool variable also occupies one byte, a WordBool variable
occupies two bytes (one word), and a LongBool variable occupies four bytes (two words).
Boolean values are denoted by the predefined constants True and False. The following relationships hold.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   72   73   74   75   76   77   78   79   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin