the Internet Windows Android

Numerical variables and data types. Delphi Data Types and Work with Double Delphi Data Type

Using data types, the programmer specifies the compiler, how to store information in the program. When declaring the variable, you must specify its type. Some types are already defined in the language, the other programmer has to be asked. In earlier programming languages, a limited number of data types was allowed, and Pascal It turned out to be one of the first languages \u200b\u200ballowing the definition in the program of new types.

User-Defined Data Types are usually set in the Program Quality Definitions or Module (Unit), but this can be done within procedures or functions. Type ads are valid within the limits of that block in which they are posted. Outside this block, it is impossible to refer to such types. Inside, they replace all external types with the same name. The announced data types can be used anywhere in the field of their visibility; It is forbidden only the reference to the specified type on itself (here, however, there is one exception regarding pointers).

Types ads in Pascal are for a compiler something like the schemes that it must remember in case, if he suddenly meets the link to one or another type in the program. In itself, the type ad does not contribute to the program.

As for VAR ads, they set the compiler some actions related to previously announced types. The type of variable limits both its values \u200b\u200band operations that can be performed with these values.

The definitions of types and variables can be placed in several places of the program components. They look as follows.

type
Typel \u003d Type Definitioni; // New data types are defined in the "Type" section. Each new one
// Type assigned a name, then it is determined through already
// Existing types.
Type2 \u003d Type__Definition2; // In one section "TYPE" you can declare several types.
// The simplest definition of the type consists of type name,
Type3 \u003d Typel; // defined earlier.
// New variables are announced in
Var // section "VAR". Each new
VAR1: Type Definitions; // variable first assigned the name, and then - type (based on
// previously defined types).
VAR2, VAR3: Type Definition4; // In one section "VAR" you can declare several variables.
// A few variables can be assigned the same type.
VAR4: TYPEL; // The program is easier to read if the variables are assigned
// Existing types.

Object Pascal syntax allows you to simultaneously construct exceptionally complex types and definition of variables. However, the definition of types in the Type sections of certain blocks makes it possible to use these types in different parts of the program. New types are determined from the types of the following categories.

  • Simple types for storing information in the form of numbers and other "ordered" values.
  • String types for storing characters sequences.
  • Structural types for simultaneous storage of information of different types.
  • Point types for indirect access to variables of specified types.
  • Procedural types to appeal to procedures and functions considered as variables.
  • Variant types for storage in one variable data of various types.

Usually type identifiers are used only when defining new types or declaration of variables. There are, however, several functions in which the type name can be used as part of the operator being executed. For example, the SizeOF function (T) returns the number of bytes occupied by the variable T.

SizeOF function is very important for writing efficient programs. Many of those defined in Object Pascal types have a very complex structure and can be in memory quite a lot of space. In this case, elements of such types are created more for the presentation of values \u200b\u200bin some logical order, and not in order to occupy a place in memory. The SizeOof feature eliminates the programmer from the need to calculate the amount of data in such cases.

Simple data types

Ordinal types
Whole types
Symbolic types
Boolean types
Enumerated types
Subadiapan types
Valid types

Any actually existing data type, no matter how difficult it seems at first glance, is simple components that the processor can manipulate. In Object Pascal, these simple data types are divided into two groups: ordinal, representing data from different volumes that the processor can easily manipulate, and valid representing approximately mathematical values. The separation of types on ordinal and valid is somewhat conditional. In the same way, simple data could be divided into numbers and not numbers. However, in the Object Pascal language, ordinal and valid data are interpreted differently, and this separation is even useful.

Ordinal types

Of the simple types of these sequences are the simplest. In these types, information is presented in the form of individual elements. The relationship between individual elements and their memory representation determines the natural relationship between these elements. Hence the name orders.

Object Pascal defines three groups of sequence types and two types defined by the user. Groups are integer, symbolic and boolean types. The sequence types defined by the user are listing and subbands.

All values \u200b\u200bof any sequence type form an ordered sequence, and the value of a variable of a sequence type is determined by its place in this sequence. With the exception of variable integer types, the values \u200b\u200bof which can be both positive and negative, the first element of any sequence type has a number 0, the second element - number 1, etc. The sequence number of the whole value is equal to the most value. The order ratio determines common for these all sequence types of surgery. Some standard functions of this type are embedded in Object Pascal. They are presented in Table. 1.1.

For all sequence types in Object Pascal, there is a type task operation to convert entire values \u200b\u200bto the values \u200b\u200bof the corresponding sequence types. If T is the name of the sequence type, and x is an integer expression, then T (x) WHO rotates the value of T with the sequence number X.

Table 1.1. Operations on ordinal types

Operation

Description

The minimum value of the ordinal type T

The maximum value of the sequential type T

The sequence number of the expression value of the sequence type. For a whole expression, it is simply its meaning. For the remaining ordinal types of ORD, the physical representation of the expression result is interpreted as an integer. Return value always belongs to one of the entire types

Previous in order value. For entire expressions equivalent to X-1

Next in order value. For whole expressions equivalent to x + 1

Reduces the value of the variable to 1. Equivalent to V: \u003d PRED (V)

Increases the value of the variable by 1. Equivalent to V: \u003d SUCC (V)

Whole types

In variable types of types, information is represented as integers, i.e. Numbers not having a fractional part. Certain types defined in Object Pascal are divided into physical (fundamental) and logical (general). When programming it is more convenient to use logical integers that set the amount of variables depending on the type of microprocessor and the operating environment in such a way that the maximum efficiency is achieved. Physical whole types should be applied only in cases where the range of values \u200b\u200band physical volume variable are primarily important. The Object Pascal defines the following entire types.

Integer
Shortint.
Smallint.
Longint.
Byte
Word.
Cardinal.

Please note that one of these entire types is called integer (Integer). It can sometimes lead to confusion, but we can easily avoid it, applying the term whole to. Type group, A Integer - to a specific type determined in the program keyword. Variables of physical integer types have different ranges of values \u200b\u200bdepending on how many memory bytes they occupy (which is equal to the value returned by the SizeOF function for this type). Ranges of values \u200b\u200bfor all physical types are listed in Table. 1.2.

Table 1.2.Physical whole types

Range meaning

Physical format

8 bits, with a sign

16 bits, with a sign

2 147 483 648-2 147 483 647

32 bits, with a sign

8 bits, no sign

16 bits, no sign

The ranges of values \u200b\u200band formats of physical integer types do not depend on the microprocessor and the operating system in which the program is performed. They do not change (or at least do not have to change) with a change in implementation or version of Object Pascal.

The ranges of values \u200b\u200bof logical integer types (Integer and Cardinal) are determined in a completely different way. As can be seen from the table. 1.3, they are not connected with the ranges of relevant physical types. Please note that the default Delphi is set to a 32-bit view.

Table 1.3.Logic whole types

Range of values

Physical format

16 bits, with a sign (smaliint)

2 147 483 648-2 147 483 647

32 bits, with a sign (Longint)

16 bits, no sign (Word)

32 bits, no sign (Longint)

All operations defined for ordinal types are performed on the whole data, but it is still more convenient to work with numbers as with numbers, and not with "non-sequential sequence types." Like the "live" numbers, the data of integer types can be folded (+), deduct (-) and multiply (*). However, some operations and functions applied to the data of integer types have a slightly different meaning.

Symbolic types

The meaning of symbolic data is obvious when they are displayed on the screen or printer. However, the definition of a symbol type may depend on what to imply under the word symbol. Typically, symbolic data types set the interaction circuit between different volumes and some standard method Coding / decoding for sharing symbolic information. In the classic language Pascal, no scheme is specified, and in specific implementations it was used that each could use each.

In the implementations of the Pascal language for the first microprocessors, a 7-bit scheme, called ASCII (American Standard Code for Information Interchange - American Standard Code for Exchange Information). This scheme is still widespread, but the information is stored, as a rule, in the 8-bit sections of memory. An additional bit doubles the number of possible characters representations, but the implementation of the extended set symbols ascii. Often are far from the standard. This version of Delphi defines a set of 8-bit characters, known as Advanced (Extended) ANSI (American National Standards Institute - American National Institute of Standards). Be that as it may, the symbolic scheme has to be perceived as the operating system perceives it. For window operating systems Microsoft is an ANSI scheme, which includes a limited number of international signs intended. In the desire to apply a more extensive set of international signs. The entire computer world proceeds to a 16-bit scheme called Unicode, in which the first 256 characters coincide with the characters defined in the ANSI scheme.

For compatibility with all these views in Object Pascal, two physical symbol types and one logical are defined.

Physical types are listed below.

Symbolic types of double word (32 bits) are missing.

The logical symbol type is called Char. In the classic language Pascal Char, the only character type. Delphi Char always corresponds to the physical type of ANSICHAR data. In American programmers, the symbol association with a single-pacted memory cell has rooted for many years so much that it often simply does not occur that other coding schemes can be used. However, discussions on the internationalization of programs in the Internet and World Wide Web can significantly change their attitude to the problem of symbolic data. Apply logical type Char, should be implemented for other microprocessors and operating systems in which Char can be defined as WideChar. When writing programs that can handle lines of any size, to specify this size it is recommended to apply the SizeOF function without specifying it hard constant. The ORD (C) function, where C is any character type variable, returns an integer value to which the S symbol is presented in memory.

Boolean types

At an early stage of training, the programmers are mastering the concept of a bit, the two states of which can be used to record information about anything representing one of two. A bit may designate 0 or 1, yes or no, turned on or off, top or bottom, stand or go. In Object Pascal, information about anything that can be represented as truth (true) or false (false) is stored in boolean variables. Total types of Chere, and they are presented in Table. 1.4.

Table 1.4.Dimensions of variables of boolean types

2 bytes (volume Word)

4 bytes (Longint volume)

By analogy with integer and symbolic types, divided into physical and logical, it is natural to assume that Bytebool, WordBool and Longbool - physical types, boolean - logical. But in this case it is not quite so. All four types are different. For Object Pascal, the BOOLEAN type is preferred, the remaining are defined for compatibility with other programming languages \u200b\u200band operating systems.

A variables of type Boolean can only be assigned True (truth) and false values. Variables byteboool, WordBool and Longbool can also receive other sequence values, intertwined usually as false in case of zero and true - with any nonzero value.

Enumerated types

Type Enum Type \u003d (First Value, Value2, Value3, Last Value);

Typically, these types of lists contain discrete values, which are not numbers, and names. Type Boolean is the simplest listed type in Object Pascal. Boolean variables can take two values \u200b\u200bexpressed by True and False names, and the type itself is defined in Object Pascal as if it is declared as follows:

Type Boolean \u003d (False, True);

Using the BOOLEAN type in Object Pascal, comparisons are performed, most of the same type of types are simply lists of unique names or identifiers reserved with a specific purpose. For example, you can create a type of MyColor (my color) with the values \u200b\u200bof MyRed, MyGreen and MyBlue (my red, my green, my blue). This is done quite simple:

Type MyColor \u003d (MyRed, MyGreen, MyBlue);

This line announced four new identifiers: MyColor, MyRed, MyGreen and MyBlue. The identifier of MyColor is marked by the sequence type, therefore, in the Object Pascal syntax, this identifier can be used everywhere where the listed types are allowed. The remaining three identifiers are MYCOLOR type values. Like symbolic I. boolean types The listened are not numbers, and the use of them like numbers does not make sense. However, the listed types are ordinal, so the values \u200b\u200bof any such type are ordered. The identifiers in the list are assigned as sequence numbers sequential numbers. The first name is assigned the sequence number 0, the second - 1, etc.

Subadiapan types

The variables of the subband type contain information corresponding to a certain dialing range of the source type values, representing any sequence type, except subadiapan. The syntax of the definition of subband type has the following form:

Type Subange Type \u003d Low Value ... High Value;

Subband variables retain all the features of the source type. The only difference is that the subband variable can be assigned only the values \u200b\u200bincluded in the specified subband. Control over this condition is given by the Range Checking Test command.

The need to explicitly define the subband type occurs infrequently, but all programmers implicitly use this design when determining arrays. It is in the form of a subband design that the scheme of the numbering of the elements of the array is set.

Valid types

In variable valid types, contains numbers consisting of integer and fractional parts. Object Pascal has six valid types. All types can represent the number 0, however, they differ in the threshold (minimum positive) and maximum valueswhich can be represented as well as accuracy (the number of significant digits) and the volume. The actual types are described in Table. 1.5.

Table 1.5. Valid types.

Whole types represent integers, i.e. Numbers whose fraction is zero. The difference between two unequal integers cannot be less than one. It is due to this that integers are used to designate discrete values, regardless of whether real objects have any attitude to the numbers. The actual types are designed to represent numbers that may have a fractional part, so they are useful for presenting values \u200b\u200bthat can be quite close, almost continuous.

Note, it is almost almost. Despite the name valid, the variables of these types differ from mathematical valid numbers. In Object Pascal, a valid type is a subset of mathematical valid numbers that can be represented in a floating point and a fixed number of numbers. For inattential programmers, the situation is exacerbated by the fact that in the standard IEEE formats (Institute of Electrical and Electronic Engi-Neers - Institute of Electric Engineers and Electrical Covers) used in Delphi programs and in general in most Windows programs, it is possible to accurately represent only numbers with a fixed number. Bit in fractional part. Surprisingly, such a simple number, like 0.1, is written in an extended IEEE format with some error, even if it is very small. Because of this, a floating point representation is somewhat inconvenient for programs in which a fixed number of decimal discharges of numerical values \u200b\u200bis preserved. This applies to programs working with "living" money.

To partially solve this problem in Object Pascal, two formats with fixed comma are defined. The COMP type (computational - computing) contains only integers in the range from -2 63 +1 to 2 63 -1, which roughly corresponds to the range from -9.2x10 18 to 9.2x10 18. When programming operations with American currency, developers usually have to look for a natural way of writing money sums, in which a whole part of the number determines the number of dollars, fractional - cents. If such values \u200b\u200bare recorded in variable type COMP will have to represent them as a whole number of cents. In this case, you should multiply the value to 100 to circulate cents to dollars, and then divide to 100 to get cents again.

These concerns can be avoided if you use the type of Currency. In this case, the task of selecting the scale will take the compiler. Physically, CURRENCY values \u200b\u200bare recorded in memory of the same volume as Comp, as integers, however, the compiler does not forget to divide the value by 10,000 (not 100!) To bring it in line with monetary sign and multiply by 10,000 before writing in memory. This provides absolute accuracy of four decimal decimal sign.

Numerical variables and data types

The Delphi programming system is a modern and very powerful tool to create programs. In this you could make sure to study the elementary capabilities of the editor of this system. Work in such an editor is not difficult, and often simply delivers the user a pleasure to the variety of your capabilities. The programs created in Delphi are quite effective, and allow you to use all the power of computing technology.

One of the most important obstacles is the volume random access memory and computer speed. The programmer always have to think about how to reduce the need of a program in memory. One way to solve this problem is to limit the number of variables used in the program, or reduce the size of the memory cells for storage.

You already know how variables of the whole and real type are declared. In addition to these variables in the Delphi system there are several more data types. They differ from each other only the size of the memory required for their storage, and, accordingly, the range of numbers that can be stored in these variables. Thus, the programmer can choose the necessary numerical type, and rationally use the memory. So what is the data types.

Data types

Any data, i.e. Constants, variables, properties, values \u200b\u200bof functions or expressions in Delphi are characterized by their types. The type determines the set of permissible values \u200b\u200bthat one or another object may have, as well as many permissible operations that apply to it. In addition, the type also defines the format of the internal representation of the data in the PC memory.

Delphi. characterized by an extensive data type structure:

We will consider with you so far only simple types.

Ordinal types

The ordinal types are characterized by the fact that each of them has a finite number of possible values. These values \u200b\u200bcan be ordered in a certain way (from here and the name of the types) and, therefore, with each of them you can compare some integer - the sequence number of the value.

The sequence types include integers, logical, symbol, listed and type-range. To any of them, the ORD (x) function is applicable, which returns the sequence number of the values \u200b\u200bof the expression X.

Whole types

Name

Length, byte

Range of values

Cardinal.

0. .. 2 147 483 647

Byte

0...255

Shortint.

128...+127

Smallint.

32 768...+32 767

Word.

0...65 535

Integer

Longint.

2 147 483 648...+2 147 483 647

Int64.

9*10 18 . ..+9*10 18

Longword.

0. . .4 294 967 295

Types of Longword and Int64 are first entered in version 4, and SMallINT and Cardinal types are missing in Delphi 1. Integer type for this version takes 2 bytes and has a range of values \u200b\u200bfrom -32768 to +32767, i.e. coincides with SMALLINT.

Standard procedures and functions applicable to whole types

Appeal

Type of result

Act

aBS (X)

Returns the X Module

cHR (B)

Char.

Returns a symbol in its code

dEC (VX [, I])

Reduces the value of VX to I, and in the absence of i - by 1

iNC (VX [, I])

Increases the value of VX to I, and in the absence of i-it 1

Hi (W)

Byte

Returns the Senior Argument Bow

Hi (I)

Also

Returns the third byte

LO (I)

Returns the younger byte argument

Lo (W)

Also

oDD (L)

Boolean.

Returns True if an argument is an odd number

Random (W)

Like the parameter

Returns a pseudo-random number, uniformly distributed in the range 0 ... (W-L)

sQR (X)

Returns the square of the argument

sWAP (I)

Integer

Changes in places bytes in the word

swap (w)

Word.

Also

Also, in addition to the arithmetic operations known to you, there are two more: Div and MOD.

d iv. - division of integers with the garbage of the fractional part. For example:

a Div b if a \u003d 10 and b \u003d 3, then the result is 3.

mod. - The remainder of the division of integers. For example:

a MOD B. if a \u003d 10 and b \u003d 3, then the result is 1

Representation of integers

In the image of integers only there are signs and numbers (the + + sign can not indicate). It is assumed a decimal number system, however, you can use hexadecimal. In this case, before the number you should put a $ sign.

Type range

All whole types refer to the so-called listed or sequence types. In any sequence type, you can select a subset of values \u200b\u200bin which all the values \u200b\u200bof the source type are included. The range type is set in the type ads by specifying the minimum and maximum values \u200b\u200bseparated by two points. Type ads are always started by the Type service word. For example:

Type PIR \u003d [1..2006];

Listed type

The type of type is set by the enumeration of the values \u200b\u200bthat it can receive. Each value is referred to as a certain identifier and is located in the list framed by round brackets, for example:

TypeColors \u003d (Red, White, Blue);

Symbol type

Symbolic type values \u200b\u200bare the set of all PC characters. Each character is attributed to an integer in the range of ... 255. This number serves as the code of the internal representation of the symbol, it returns the ORD function.

For an encoding in Windows, an ANSI code is used (named American National Standard Institute - the American Institute for Standardization, which suggested this code). The first half of the PC characters with codes 0 ... 127 corresponds to Table 7.3. The second half of the symbols with codes 128 ... 255 is changing for various fonts. Standard Windows Fonts Arial Cyr, Courier New Cyr and Times New Roman. To represent the symbols of Cyrillic (without letters "E" and "E") use the last 64 codes (from 192 to 256): "A" ... "I" are encoded by the values \u200b\u200bof 192..223, "A" ... "I "- 224 ... 255. The characters "E" and "E" have, respectively, codes 168 and 184.

Symbol encoding in accordance with the ANSI standard

The code

Symbol

The code.

Symbol

The code.

Symbol

The code

Symbol

Zone

ETH

F.

-

/

DC 4.

F.

Symbols with codes 0 ... 31 belong to service codes. If these codes are used in the symbolic text of the program, they are considered spaces.

CHAR type applications are applicable relationships, as well as embedded functions:

CHR (B) - CHAR type function; converts the expression into the BYTE type into the symbol and returns it to its value;

Upcase (CH) - CHAR type function; Returns a capital letter if the CH is a lowercase Latin letter, otherwise the symbol itself returns the source character for Cyrillic).

Types of real types

In contrast to the ordinal types, the values \u200b\u200bof which are always compared with a number of integers and, therefore, are absolutely precisely precisely precisely, the values \u200b\u200bof the real types determine an arbitrary number only with some finite accuracy depending on the internal format of the real number.

Types of real types

Length, byte

Name

Number of meaning digits

Range of values

8

4

8

10

8

8

Real

Single

Double.

Extended

Comp

Currency.

15…16

7…8

15…16

19…20

19…20

19…20

5.0 * 10E-324 ... 1.7 * 10E308

1.5 * 10E-45 ... 3.4 * 10E38

5.0 * 10E324 ... 1.7 * 10E308

3.4 * 10-4951 ... 1.1 * 10E4932

2e63 ... + 2e63-1

+/-922 337 203 685477,5807

In previous versions of Delphi 1 ... 3 Type Real occupied 6 bytes and had a range of values \u200b\u200bfrom2, 9 * 10-39 to 1.7 * 10 38. Versions 4 and 5 This type is equivalent to Double type. If required (for compatibility purposes), use the 6-Bail Real, you need to specify the compiler directive (SREALCOMPATILITY ON).

As can be seen from the previous table. Total number Delphi. It takes from 4 to 10 adjacent bytes and has the following structure in PC memory:

S.

E.

M.

Here s is a sign discharge; e - exponential part; contains binary order; M - Mantissa number.

Mantissa M has a length of 23 (for Single) to 63 (for extended) binary discharges, which provides accuracy of 7 ... 8 for Single and 19 ... 20 for extended decimal digits. The decimal point (comma) is meant before the left (senior) discharge of the mantissa, but under the actions with the number, its position is shifted to the left or right in accordance with the binary order of the number stored in the exponential part, so actions on real numbers are called a floating point arithmetic (comma) .

Note that the arithmetic coprocessor always processes the numbers in the extended format, and three other real types in this case are obtained by simple truncation of the results to the desired dimensions and are used mainly to save memory.

Built-in mathematical functions presented in the following table can be used to work with real data provided in the following tab. In this table, Real means any real type, Integer - any type.

Standard mathematical functions Delphi.

Appeal

Type of parameter

Type of result

Note

aBS (X)

Real, Integer

Type of Real Argument

Argument module

N \u003d 3.141592653 ...

Arctan (X)

Arcthangence (value in radians)

cOS (X)

To same<<

To same<<

Cosine, angle in radians

exp (x)

Exhibitor

fRAC (X)

Fractional part of the number

int (x)

The integer part of number

lN (X)

Natural logarithm

Random

Pseudo-random number, evenly distributed in the range of 0 ...

Random.fx)

Integer

Integer

Pseudo-random integer, uniformly distributed in the range of 0 ... (x-1)

Randomize.

Initiation of the generator of pseudo-random numbers

sIN (X)

Real

Real

Sinus, angle in radians

sQR (X)

To same

To same

Square argument

sQRT (X)

Square root

Note The pseudo generator of random numbers is a function that takes some integer called basic, changes, its discharges according to a specific algorithm and gives a new number. At the same time, the new number becomes basic in the following handling of functions; etc. (as the algorithm of the procedure does not change: during its work, the numbers are called pseudo-random.) In the System system module, which is automatically available to any program, the base number is stored in a variable named Randseek and always has an initial value of 0. This is It means, with a serial access to the Random in different, programs (or with several runs of one program), one and the same sequence of pseudo-random numbers will always fall.

Representation of real numbers

The real numbers contain in their image point and / or indicator (symbol E or E), for example:

X \u003d -0.5;

Y \u003d 1.34;

Z \u003d -1 E -5;

W \u003d 7.5 E +15;

Data type conversion functions

Round (X. ) - rounding the real number to the nearest whole. The function argument is the value of the real type, and the result is rounded to the nearest integer value of the type of Longint. If the result goes over the range of Longint values, then an error will occur when executing the program.

Trunc (X. ) - Getting the whole part of the real number. Result type - Longint. If the result goes over the range of Longint values, then an error will occur when executing the program.

Type date-time

The type of date-time is determined by the standard TDATETIME identifier and is designed for simultaneous storage and date, and time. In the internal representation, it occupies 8 bytes and like Currency is a real number with a fixed fractional part: in the whole part of the date the date is stored in the fractional time. The date is defined as the number of days past from December 30, 1899, and time - as part of the day past from 0 hours, so the value of 36444,837 corresponds to the date 10.10.1999 and time 20:05. The number of days can be negative, however, the values \u200b\u200bare smaller -693594 (corresponds to the date 00.00.0000 from the Nativity of Christ) are ignored by the dates conversion functions to the string type.

The same operations are defined above the type of TDATETIME as the real numbers, and constants and variables of the integer and real types can participate in the expressions of this type.

Subprograms listed in the following table are used to work with the date and time.

Subprogrammes for working with date and time

Function. Date: TDATETIME;

Function. DateTostr (D: TDATETIME): String;

Function. DateTimeTostr (D: TDATETIME): String;

Function. FormatDateTime (Format: String;

VALUE (TDATETIME): String;

Function. Now: tdatetime;

Function. Time: TDATETIME;

Function. TIMETOSTRFT (TDATETIME): String;

Returns the current date

Converts date in the string of characters

Converts the date and time in the string of characters

Converts a date and time from the Value parameter in the string of characters in accordance with the format parameter specifiers (see explanations in clause 7.3.)

Returns the current date and time

Returns the current time

Converts time to row

Built-in data types in Delphi language include types of integers, valid, symbols, strings, pointers, booleans.

Ordinal types. Order (Ordinal) types are called those in which the values \u200b\u200bare ordered, and for each of them you can specify the preceding and subsequent values.

Structural types. Structural types include sets, arrays, entries, files, classes, interfaces.

Types of data. In variable types of types, information is represented as integers, i.e. Numbers not having a fractional part.

Table 1 Operations on ordinal types

Operation

Description

The minimum value of the ordinal type T

The maximum value of the sequential type T

The sequence number of the expression value of the sequence type. For a whole expression, it is simply its meaning. For the remaining ordinal types of ORD, the physical representation of the expression result is interpreted as an integer. Return value always belongs to one of the entire types

Previous in order value. For entire expressions equivalent to X-1

Next in order value. For whole expressions equivalent to x + 1

Reduces the value of the variable to 1. Equivalent to V: \u003d PRED (V)

Increases the value of the variable by 1. Equivalent to V: \u003d SUCC (V)

table 2

Range of values

2147483648 -- 2147483647

8 bits, unsightened

16 bits, unsightened

32 bits, unsighteous

There is also a type such as Integer, which is equivalent to Longint type. Its range from -2147483648 to 21474836478. It takes 4 bytes in Pämyat. The mains are Integer and Cardinal, so in most cases it is desirable to use these types.

All operations defined for sequence types are performed above all data. Operations on whole types:

Table 3.

Valid data types. In variable valid types, contains numbers consisting of integer and fractional parts.

Table 4.

The main provision of maximum performance is the type REAL, which is currently equivalent to Double type.

Table 5 Functions of valid types

Return value

Absolute value x.

Arcthangence H.

Cosine x (x is expressed in radians, and not in degrees)

Exponential function from x

Fractional part x.

Whole part x. Despite the name, returns a valid value (floating semicolon), i.e. Just sets zero in fractional part

Natural logarithm from x

Pi number (3.1416 ...)

The nearest K x is integer. Returns the value of the whole type. The condition "nearest to x" does not work if the upper and lower values \u200b\u200bare equidistant (for example, if the fractional part is exactly 0.5). In these cases, Delphi shifts the solution to the operating system. Typically, Intel processors solve this problem in accordance with the IEEE recommendation rounded towards the nearest even integer. Sometimes this approach is called "banker rounding"

Square x, i.e. X * X.

Square root from x

Whole part x. In contrast to INT returning

Symbolic data types. Symbolic types are designed to store one character.

Table 6.

Booleans data types. Variables of Boolean data types represent logical values, for example, true (truth) and false.

Table 7 Sizes of Boolean Types

2 bytes (volume Word)

4 bytes (Longint volume)

An array is a data structure, which is a set of variables of the same type that have a common name. Arrays are conveniently used for storage uniform in nature, such as tables and lists.

Announcement of Massiva

An array, like any program variable, must be declared before using the variable ads. In general, the instruction of the declaration of the array aligns as follows:

Name: [Nizhny_Index..pine_Index] of Type

where: the name is the name of the array;

array is a reserved word Delphi, denoting that the announced name is the name of the array;

nizhny_index and Upper_Index - Average constants that determine the range of changes in the index of array elements and implicitly, the number of elements (size) of the array;

type - type of array elements.

What do not write in the books according to Delphi Grigoriev A. B.

3.2.2. Types of Delphi

In Delphi there are four real types: Single, Double, Extended and Real. Their general format is the same (Fig. 3.1, a).

A sign is always one bit. It is zero for positive numbers and a unit for negative. As for the size of the mantis and the exhibitors, it is in them a distinction between types.

Before switching to specific numbers, consider in more detail the type Real, making a small excursion to this. Real is the standard type of Pascal language, which was present there initially. When Pascal was created, the processors have not yet had built-in support for real numbers, so all operations with type REAL are reduced to operations with integers. Accordingly, the size of the fields in the REAL type was selected as to optimize these operations.

a) General view of the real number

b) binary representation of the number of Single type

Fig. 3.1. Storing a real number in memory

Intel 8086/88 microprocessor and its improved options - 80286 and 80386 - also did not have hardware support for real numbers. But the systems on the basis of these processors had the possibility of connecting the so-called coprocessor. This microcircuit worked with memory through the main processor tires and provided hardware support for real numbers. In the middle hand systems, the nest of the coprocessor was usually empty, since it reduced the price (of course, insert the coprocessor there was no problem). For each central processor, their coprocessors were produced, labeled Intel 8087, 80287 and 80387, respectively. There were even coprocessors produced by other firms. They worked faster than Intel's coprocesses, but appeared on the market later. The type of real numbers supported by coprocessors does not coincide with REAL. It is determined by the IEEE standard (Institute of Electrical and Electronics Engineers).

To provide IEEE type support in its systems, Borland enters TURBO PASCAL types Single, Double and Extended. Extended is the main for coprocessor type, A Single and Double are obtained from it a very simple truncation. The system of the coprocessor commands allows you to work with these types: when loading the number of type Single or Double to the internal register of the co-processor, the latter converts them to Extended. On the contrary, when unloading the numbers of these types from the register to memory, the coprocessor fees them to the desired size. The internal operations are always executed with the data type extended (however, this rule has an exception on which we will focus later, after a detailed consideration of the format of various types). Single and Double allow you to save memory. None of them also coincides with the type Real. In systems with coprocessors, new types are processed markedly (2-3 times) faster than Real (this is based on the fact that the type of REAL after the corresponding transformation is also processed by the coprocessor; if we compare the processing of type extended on the machine with a coprocessor and real on the machine without The coprocessor, then there on individual operations achieved the difference in speed at about 100 times). For programs with these types can be performed in systems without coprocessor, it is possible to connect a coprocessor software emulator to them. Processing these types by emulator was slower than Real processing.

Starting from the 486th Intel series takes a course on the integration of the processor and the coprocessor in the same chip. The percentage of marriage in chips is too large, so Intel goes to cunning: if the chips have marriage only in the coprocessor part, then jumpers blocking the coprocessor and the chip are being burned on this crystal, and the microcircuit is sold as a 80486SX processor, which has no built-in coprocessor (unlike the full version, which was called 80486dx). There were also inverse situations when the coprocessor of damage did not have, but the processor was inoperable. Such chips turned into a "coprocessor 80487". But this is from the field of exotic, and, according to our information, this coprocessor did not reach Russia.

The Pentium processor in all its own options had a built-in floating point computing unit (FPU - Floating Point Unit), and a separate coprocessor did not need it. Thus, with the arrival of this processor, the REAL type remained only for backward compatibility, and the types of Single, Double and Extended were published. Starting with Delphi 4, the type of Real becomes synonymous with a double type, and the old 6-byte type receives the name Real48.

Note

There is a compiler directive ($ realcompatibility ON / OFF), when turned on which (by default it is disabled) Real becomes synonymous with REAL48, not double.

The dimensions of the fields for various real types are indicated in Table. 3.1.

Table 3.1. Field dimensions in real types

A type Size type, bytes Mantissa size, bits Exhibitor size, bits
Single 4 23 8
Double. 8 52 11
Extended 10 64 15
Real 6 40 7

Other parameters of real types, such as range and accuracy, can be found in the Delphi Help.

From the book, programming language with # 2005 and platform.net 2.0. by Troelsen Andrew.

Types characterized by values, reference types and assignment operator Now read the following MAIN () method and consider its output shown in Fig. 3.12.Static Void Main (String Args) (Console.WriteLine ("*** Types characterized by value / reference types ***"); Console.WriteLine (-\u003e Creating P1 "); mypoint

From the book Tips on Delphi. Version 1.0.6. Author Ozers Valentin

Types characterized by values \u200b\u200band containing reference types Now that you feel the difference between types characterized by value, and reference types, let's consider a more complex example. Suppose that there is the following reference type (class),

From the book of the Internet Solutions from Dr. Bob author Svort Bob

Types characterized by values \u200b\u200band reference types: Final Notes To complete the discussion of this topic, learn the information table. 3.8, which provides a brief summary of the main differences between the types characterized by the value, and reference types. Table

From the book Delphi. Tricks and effects Author Chirtik Alexander Anatolyevich

From the book Fundamental algorithms and data structures in Delphi Author Baknell Julian M.

1.3.3. Delphi and CGI In this chapter, I will tell you how to write a simple Delphi CGI app, without using Web Modules or other Client / Server modules. The first CGI abbreviation means Common Gateway Interface, and this is only a name to transfer information from the client to the server. On the client side it

From the book World InterBase. Architecture, administration and development of database applications in InterBase / Firebird / Yaffil Author Kovyzin Alexey Nikolaevich

2.1.1. Delphi and HTML My main tool developers are Delphi, and we will write Delphi Database Html Expert in this chapter. Delphi allows you to connect to almost the database of any format. Using BDE to paradox and dbase, with ODBC, for example, access, and using SQL Links to large DBMS type

From the book Delphi Virtual Library of the author

9.3. Using OLE in Delphi Like many modern programming environments, Delphi supports the ability to automatically develop applications operating with various Som services or servers. For a deeper understanding of the principles of the application,

From the book Description of the language Pascalabc.net Author Collective Roughard

Types of arrays in Delphi in Delphi there are three types of arrays supported by the language. The first is a standard array that is declared using the ARRAY keyword. The second type was first introduced in Delphi 4 as an imitation of what was a long time ago available in Visual Basic, - Dynamic

From the book ABC Pascal Programming Language Author Flowers Alexander Stanislavovich

Type of data types to real types (they are also called the types of floating point numbers) include Float and Double Precision. Immediately follow the reader from using the Float type - its accuracy is insufficient for storing most fractional values. Especially ne.

From the book of the author

Questions on Delphi 2.0 What's new in Delphi 2.0 comparing with Delphi 1.0? The version of Delphi 1.0 released in February 1995 has become the first Windows tool that combines the optimizing compiler, the TWO-WAY-Tools visual development mechanisms and a scalable database processing architecture.

From the book of the author

What's new in Delphi 2.0 comparing with Delphi 1.0? The version of Delphi 1.0 released in February 1995 has become the first Windows tool that combines the optimizing compiler, the TWO-WAY-Tools visual development mechanisms and a scalable database processing architecture. Today hundreds

From the book of the author

From the book of the author

From the book of the author

The real types below is a table of real types, containing their size, number of meaningful digits and range of valid values: type size, bytes Number of meaning digits Range of values \u200b\u200bREAL 8 15-16 -1.8? 10308 .. 1.8? 10308 Double 8 15-16 -1.8 10308 ..

The text of the program in Delphi is formed using letters, numbers and special characters. Letters are uppercase and lowercase symbols of the Latin alphabet and the underscore symbol: A B C D E F G H I J K L M K L x Y Z A B C D U V W x Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ The numbers are represented by the standard Arab form of recording: 0 1 2 3 4 5 6 7 8 9 Special characters + - * / \u003d ,. :; "() () @ # $ & ^ is used mainly as signs of arithmetic operations, separators, limiters, etc. From special characters, compound symbols are formed: \u003d.. (..) (* *) //: \u003d They Serve, in particular, to denote operations such as "not equal", "greater than or equal", specifying ranges of values, commenting program, etc. Alphabet

The same number can be recorded by a variety of ways, for example: 15 (whole) 15. 0 (real with a fixed point) 1. 5 E 01 (substantial floating point) $ F (hexadecimal) in Delphi Language It is possible to apply all methods Entries, but most often use whole and real numbers. The integers consist only of numbers and sign + or -. If the sign is omitted and the number is not equal to 0, then it is considered as a positive, for example: 0 (0 interpreted as an integer) 17 (positive integer) -39 (negative integer) numeric data types

The real numbers contain a whole and fractional part, separated by a point: 0. 0 (0 interpreted as a real number) 133. 5 (positive real number) -0. 7 (negative real number) The real numbers can be represented in two forms: with a fixed and floating point. The form with a fixed point coincides with the usual record of numbers: 27800 (the point at the end of the number is omitted) 3. 14 Floating point (exponential form) is used when working with very large or very small numbers. In this form, the number facing E is multiplied by 10 to the degree indicated after E: 7. 13 E + 14 (7. 13 x 1014) 1. 7 E-5 (1. 7 x 10 -5) 3. 14 E 00 (3. 14 x 100 \u003d 3. 14) The number facing the letter E is called a mantissa, and the number after the letter E is ordinary. Numeric data types

With the help of comments, you can explain the logic of the work of your program. The comment is passed by the compiler and can be in any place of the program. The comment is: (any text in curly brackets) (* any text in brackets with asterisks *) // Any text from a double inclined line to the end of the line if the symbols (or (* immediately goes the dollar $, then the text in brackets is considered not Comments, and a compiler directive. Examples of such directives: ($ Optimization ON) ($ Warnings ON) ($ RangeChecks Off) Comments

The program in the execution process always processes kakelibo data. Data may be integer and fractional numbers, symbols, strings, arrays, sets, etc. So the computer is just a machine for which the data is a sequence of zeros and units, it must absolutely "know", how to interpret them. For this reason, all data in the Delphi language is divided into types. The data type indicates which values \u200b\u200bof data and which operations can be performed with them. Each data type corresponds to a certain amount of memory that is required to place data. For example, in the Delphi language there is a BYTE data type. The data of this type take values \u200b\u200bin the integer range from 0 to 255, can participate in the operations of addition, subtraction, multiplication, division, and occupy 1 byte of memory. Data types

All data types in Delphi can be classified as follows: Simple data types. They, in turn, are divided into ordinal and real data types. The ordinal types include integer, symbolic, boolean, listed, etc. Types; Temporary data type. Serves to represent date and time values; String data types. Serve to represent sequences from characters, such as text; Composite data types. Form on the basis of all other types. These include arrays, sets, records, files, classes and references to classes; Procedural data types. Allow manipulation of procedures and functions as data of the program; Indexing data types. These types are stored the addresses of other data (lists, trees, etc.); Data type with non-permanent values. Serves to represent values \u200b\u200bwhose type is unknown in advance; With it, it is easy to work with a list of diversified values; Classification of data types

Consider the form of describing variables, constants and types. Description of types: Type \u003d; Description Constant: Const: \u003d; Description of variables: var :; Data Description Form

An example of writing a constant: const delphi. Language \u003d "Object Pascal"; Kylix. Language \u003d Delphi. Language; Yard \u003d 914. 4; Foot \u003d 304. 8; Seconds. In. Minute \u003d 60; Seconds. In. HOUR \u003d Seconds. In. Minute * 60; // Set the SECONDS constant. In. Day \u003d Seconds. In. HOUR * 24; // As an expression when declaring a constant, you can specify its type: Const Percent: Double \u003d 0. 15; File. Name: String \u003d "Help. TXT"; Such constants are called typed; Their main purpose is to declare the constant values \u200b\u200bof the composite data types. Constant description

In addition to standard data types, Delphi language supports types defined by the programmer. The new data type is determined using the reserved type of Type, followed by the type identifier, a sign of equality and description. For example, you can define a new type: Type Tunicode \u003d WIDE. Char; Tfloat \u003d double; Tdirection \u003d (North, South, East, West); It is easy to notice that the identifiers of new types in the example begin with a capital letter T (the first letter of the word type). Such an agreement on the types of programmer is adopted by the developers of the Delphi environment, but it is not strict. Nevertheless, we recommend it to adhere to, as it contributes to the easier perception of the source code of the program. Description of types

Whole type of range Shortint Smallint Integer Longint Cardinal int 64 Byte Word Longword -128. . 127 sign 8 -bit -32768. . 32767 sign 16 -bit -2147483648. . 2147483647 Sign. 32 -bit 0.. 4294967295 Unless sign 64 -bit -263. . 263 -1 sign 64 -bit 0.. 255 No sign 8 -bit 0.. 65535 No Sign 16 -bit 0.. 4294967295 No Sign 32 -bit Format Simple Data Types

Type range of values. Real 48 Single Double Extended 5. 0 x 10 -324. . 1. 7 x 10308 15 -16 2. 9 x 10 -39. . 1. 7 x 1038 11 -12 1. 5 x 10 -45. . 3. 4 x 1038 7 -8 5. 0 x 10 -324. . 1. 7 x 10308 15 -16 3. 6 x 10 -4951. . 1. 1 x 104932 19 -20 Digit COMP - 9223372036854775808. 9223372036854775807 19-20 CURRENCY - 922337203685477. 5808. 922337203685477. 5807 19- 20 Real Types byte 8 6 4 8 10 8 8

Symbolic types are used to describe the data, the value of which is the letter, digit, punctuation sign and other characters. There are two fundamental symbol data types: ANSI. Char and Wide. Char. They correspond to two different symbol encoding systems. AnSi type data. CHAR occupy one memory byte and encode one of 256 possible characters of the AnSI extended code table, while WIDE data. CHAR occupy two memory bytes and encode one of the 65536 Unicode code table symbols. UNICODE code table is a dual-byte symbol encoding standard. The first 256 symbols of the Unicode table correspond to the ANSI table, so ANSI data type. CHAR can be viewed as a subset of WIDE. Char symbol type

Fundamental data types: Data type Memory capacity (byte) ANSI. Char 1 Wide. Char 2 General Data Type: Data Type Memory (bytes) Char 1 (but it can become equivalent to WIDE) Logical data type var good_file: boolean; Boolean data types byte. BOOL, WORD. BOOL and LONG. BOOL was introduced into the Delphi language specifically for compatibility with other languages, in particular with C and C ++ languages. All Boolean data types are compatible with each other. Symbolic and logical data type

Example. Description of the constant and variable symbol type. Const ch_p \u003d 'a'; // Symbolic constants ch_l: char \u003d 'f'; CH_K: WIDE. Char \u003d '5'; Var ch_l: char; // Symbolic variable in the program values \u200b\u200bof variables and constants of character types are concluded in apostrophes (not to be confused with quotes!), for example: Symbol: \u003d "A"; // SYMBOL is assigned letter A An example of symbolic data types

Rows are a dynamic array of characters. String - length not more than 256 characters. Wide. String - Length of more than 256 characters. The information is considered a string if it is closed into single quotes: 'Mary It Bread' - the "Mary It Bread 'string is not a string example. Determine the constant and variable of a string type. Const s_weether \u003d 'cold ...'; VAR S 1: C_WETHER; S 2: String; String data type

Listed type. The listed data type is a list of values \u200b\u200bthat can receive a variable of this type. Each value is assigned to the identifier used in the program to specify this value. Example. Type TColors \u003d (Red, White, Blue); TMONTH \u003d (JNU, FEB, MAR, APRIL, MAY, JUN, JUL, AGU, SEP, OCT, NOV, DEC); Tdirection \u003d (North, South, East, West); var MONTH: TMONTH; Direction: TDIRECTION; Begin Direction: \u003d North; end. Enumerated data type

In fact, the identifiers of the values \u200b\u200bof the listed type are integer constants. By default, the first constant is 0, the second is 1, etc. It is possible to explicitly assign the value of the Type Tsize identifier. Unit \u003d (byte \u003d 1, kilobyte \u003d 1024 * byte, megabyte \u003d kilobyte * 1024, Gigabyte \u003d Megabyte * 1024); The maximum power of the listed type is 65536 values, so in fact the listed type specifies some subset of the whole type of Word and can be considered as a compact announcement of the group of integer constants with the values \u200b\u200bof 0, 1, etc.

Interval data types The interval data type is set by two constants that limit the range of values \u200b\u200bfor variables of this type. Both constants should belong to one of the standard sequence types (but not real and not string). Example: Type Tdigit \u003d 0.. nine; Digit \u003d "0". . "nine"; Dig 2 \u003d 48.. 57; VAR DIGIT: TDIGIT; MONTH: 1.. 12; Begin Digit: \u003d 5; Digit: \u003d 10; // Error! Exit the boundaries of the END range; Interval or type-range.

The difference between this way of creating a type and common (without word type) will manifest when studying arrays, records and classes. Bare forward and give an example: Type TType 1 \u003d Array of Integer; TTYPE 2 \u003d Type TType 1; VAR A: TTYPE 1; B: TTYPE 2; Begin B: \u003d a; // Error! end. In the example, the variables A and B are incompatible with each other because of the word Type in the description of the TType type 2. If the variables A and B belong to simple data types, the assignment operator will work. Special data types

An array is a composite data type consisting of a fixed number of elements of the same type. To describe the array, the phrase array of is designed. After the word array in square brackets, the boundaries of the array are written, and after the word of the elements of the array: Type Tstates \u003d Array of String; TCOORDINATES \u003d Array of Integer; Const Coordinates: TcoordInates \u003d (10, 20, 5); (3 Integers) Var States: TStates; (50 Strings) Symbols: Array of Char; (81 characters - without type definition) to access a separate array element, you need to specify its index in square brackets, for example Symbols: \u003d 'ё'; Please note that the initialization of the elements of the array occurs in parentheses through the comma. Arrays

The arrays declared above are one-dimensional, as there are only one index. One-dimensional arrays are usually used to represent a linear sequence of elements. If, when describing the array, two index is specified, the array is called two-dimensional if N indexes are N-dimensional. Two-dimensional arrays are used to present the table, and N-dimensional - to represent spaces. Here is an example of a table ads consisting of 5 columns and 20 lines: var table: Array of Array of Double; The same can be recorded in a more compact form: VAR Table: Array of Double; To access the separate element of the multidimensional array, you need to specify the value of each index, for example, Table or in more compact entry multidimensional Table arrays

Example. Description of the two-dimensional dynamic array of elements of the BYTE type in the CON variable. Var Son: Array of Byte; Example. Multidimensional arrays. VAR MBON: Array of Byte; // Four-dimensional Type TMY_MAS \u003d Array of Byte; // Type - two-dimensional array VAR MBON 1: Array of TMY_MAS; // Four-dimensional (two-dimensional array of two-dimensional arrays) C: Array of Real; // Three-dimensional dynamic MBON array - element of the MBON MBON 1 array element - the element of the MBON 1 C - // the first element of the dynamic array examples of dynamic arrays

The set is a composite data type to represent a set of some elements as a whole. The range of set values \u200b\u200bis a set of all kinds of subsets composed of its elements. All elements of the set should belong to a single-byte order type - the basic type. To describe the multiple type, the phrase is used SET OF, after which the basic type of set is recorded: Type Tletters \u003d Set of "A". . "Z"; Var Letters: Tletters; Symbols: Set of Char; In expressions, the values \u200b\u200bof the elements of the set are indicated in square brackets: ,, ["a", "b", "c"]. If the set has no items, it is called empty :. Example: Const Vowels: Tletters \u003d ["a", "e", "i", "o", "u"]; Begin Letters: \u003d ["a", "b", "c"]; SYMBOLS: \u003d; (empty set) End. The number of elements of the set is called power. The power of the set in the Delphi language may not exceed 256. sets

Src \u003d "https: //syt/presentation/20070619_133096976/image-25.jpg" alt \u003d "(! Lang: When working with sets, the use of relations (\u003d ,,,\u003e \u003d, when working with sets is allowed to use relationship operations ( \u003d,\u003e \u003d,). Two sets are considered equal if they consist of the same items. The order of the elements in compared sets does not have any values. Two sets A and B are considered not equal if they differ in power or by value although One element would be a result of True \u003d True \u003d True \u003d True Accessories (\u003e \u003d, \u003d B is true if all elements of the set B are contained in a set A. Expression A

Operation in. Used to check the element belonging to the specified set. Usually applied in conditional operators. 5 In \u003d True 5 IN \u003d FALSE The IN Operation allows you to effectively and clearly perform complex tests of conditions, while replacing dozens of other operations. For example, the operator if (x \u003d 1) or (x \u003d 2) or (x \u003d 3) or (x \u003d 5) or (x \u003d 7), then can be replaced by a shorter: if x in then Operation in sometimes trying to record with denial : X NOT IN S. This entry is erroneous, since two operations follow in a row. The correct entry is: not (x in s). Operation of IN.

Combining sets (+). The combination of two sets is the third set containing the elements of both sets. + \u003d + \u003d Intersection of sets (*). The intersection of two sets is the third set, which contains elements that are included simultaneously in both sets. * \u003d * \u003d Set differences (-). The difference of two sets is the third set, which contains the elements of the first set, not included in the second set. - \u003d - \u003d In the Delphi language, two standard procedures include Include and Exclude, which are designed to work with sets. The procedure Include (S, I) includes in the set S element I. The EXCLUDE procedure (S, I) excludes from the set s Element I. They duplicates the operation - / + with the only difference that they work with one element and make it more efficiently. Association, intersection, difference