• Features of real numbers in Delphi. Structural data types Delphi real types

    Data type

    The program can operate with data of various types: integer and fractional numbers, characters, character strings, logical values.

    Integer type

    The Delphi language supports seven integer data types: shortint, smailint, Longint, Int64, Byte, word and Longword, a description of which is given in Table. 1.1.

    Table 1.1. Integer types

    Type

    Range

    Format

    Shortint

    128-127

    8 bits

    Smallint

    32 768 - 32 767

    16 bits

    Longint

    2 147 483 648 - 2 147 483 647

    32 bits

    Int64

    2 63 - 2 63 - 1

    64 bits

    Byte

    0-255

    8 bits, unsigned

    Word

    0-65 535

    16 bits, unsigned

    Longword

    0 - 4 294 967 295

    32 bits, unsigned

    Object Pascal also supports the most universal integer type -Integer which is equivalent Longint.

    Real type

    The Delphi language supports six real types: Reai48, single, Double, Extended, comp, Currency. The types differ in the range of acceptable values, the number of significant digits and the number of bytes required to store data in computer memory (Table 1.2).

    Table 1.2. Real (fractional) types

    Type

    Range

    Significant figures

    Bytes

    Real48

    2.9x 10 -39 -1.7x10 38

    11-12

    06

    Single

    1.5 x 10 -45 -3.4x 10 38

    7-8

    04

    Double

    5.0x10- 324 -1.7x10 308

    15-16

    08

    Extended

    3.6x10- 4951 -1.1 x10 4932

    19-20

    10

    Comp

    2 63 +1 - 2 63 -1

    19-20

    08

    Currency

    922 337 203 685 477.5808 --922 337 203 685 477.5807

    19-20

    08

    The Delphi language also supports the most universal real type -Real, which is equivalent to Double.

    Character type

    The Delphi language supports two character types: Ansichar and Widechar:

    • Ansichar type is ANSI characters that correspond to numbers in the range from 0 to 255;
    • The widechar type is Unicode characters and corresponds to numbers from 0 to 65,535.

    Object Pascal also supports the most universal character type - Char, which is equivalent to Ansichar.

    String type

    Delphi language supports three string types: shortstring, longstring

    • WideString:
    • the shortstring type is a string with a length from 0 to 255 characters statically allocated in computer memory;
    • The Longstring type is a string dynamically allocated in memory, the length of which is limited only by the amount of free memory;
    • The WideString type is a dynamically allocated string whose length is limited only by the amount of free memory. Each character in a WideString is a Unicode character.

    In Delphi, the string identifier can be used to denote a string type. The string type is equivalent to the shortstring type.

    Boolean type

    A Boolean value can take one of two values: True or False. In Delphi, Boolean values ​​are classified as type Boolean.

    Variable

    A variable is an area of ​​memory that contains data that a program operates on. When a program manipulates data, it actually operates on the contents of memory cells, i.e., variables.

    In order for a program to access a variable (memory area), for example, in order to obtain initial data for a calculation using a formula or to save the result, the variable must have a name. The variable name is created by the programmer.

    As a variable name, you can use a sequence of Latin letters, numbers and some special characters. The first character in a variable name must be a letter. Space cannot be used in a variable name.

    Note that the Delphi compiler does not distinguish between uppercase and lowercase letters in variable names, so the names SUMMA, Summa, and summa refer to the same variable.

    It is desirable that the variable name be logically related to its purpose. For example, variables designed to store the coefficients and roots of a quadratic equation, which in general form is traditionally written

    ax2 + bx + c = 0

    it is quite logical to assign names a, b, c, x1 and x2. Another example. If the program has variables designed to store the purchase amount and discount amount, then these variables can be given names

    TotalSumm and Discount or ObSumma and Skidka.

    In Delphi, every variable must be declared before it can be used. With the help of a declaration, not only the fact of the existence of a variable is established, but its type is also specified, which also indicates the range of permissible values.

    In general, a variable declaration instruction looks like this:

    Name: type;

    Where:

    • name - variable name;
    • type - the type of data the variable is intended to store.

    Example:

    a: Real; b: Real; i: Integer;

    In the examples given, two variables of type real and one variable of type integer are declared.

    In the program text, the declaration of each variable is usually placed on a separate line.

    If the program has several variables of the same type, then the names of these variables can be listed on one line, separated by commas, and the type of the variables can be indicated after the name of the last variable, separated by a colon, for example:

    a,b,c: Real; x1,x2: Real;

    Constants

    There are two types of constants in Delphi: regular and named.

    A regular constant is an integer or fractional number, a string of characters or a single character, or a Boolean value.

    Numeric constants

    In the program text, numerical constants are written in the usual way, that is, in the same way as numbers, for example, when solving mathematical problems. When writing fractional numbers, a dot is used to separate the whole and fractional parts. If the constant is negative, then a minus sign is placed immediately before the first digit.

    Below are examples of numeric constants:

    123 0.0

    524.03 0

    Fractional constants can be represented as a floating point number. The floating-point representation is based on the fact that any number can be written in algebraic form as the product of a number less than 10, called the mantissa, and a power of ten, called the exponent.

    "2.4"

    "D"

    Here you should pay attention to the constant "2.4". This is precisely a character constant, i.e. a string of characters that represents the number “two point four”, and not the number 2.4.

    Logical constants

    A logical statement (expression) can be either true or false. True corresponds to the constant True, and the value "false" corresponds to a constant False.

    Named constant

    A named constant is a name (identifier) ​​that is used in a program instead of the constant itself.

    A named constant, like a variable, must be declared before it can be used. In general, the instruction for declaring a named constant looks like this:

    constant = value;

    Where:

    • constant - the name of the constant;
    • value - the value of the constant.

    Named constants are declared in the program in the constant declaration section, which begins with the word const. Below is an example of declaring named constants (integer, string and fraction).

    const

    Bound = 10;

    Title = "Running speed";!}

    pi = 3.1415926;

    After declaring a named constant in a program, you can use its name instead of the constant itself.

    Unlike a variable, when declaring a constant, the type is not explicitly specified. The type of a constant is determined by its type, for example:

    • 125 - integer constant;
    • 0.0 - constant of real type;
    • "execute" is a string constant;
    • "\" is a character constant.


    In previous lessons, we casually got acquainted with data types. All this time we were talking about simple types. Today we will summarize what we have covered previously, and also get acquainted with new material that you need to know within the framework of the topic “Simple data types”. There are a variety of reasons why you need to be smart about choosing data types for the variables you use in your programs. First, having the variety of available types at hand and skillfully managing them, you can reduce the amount of memory required by the program to operate. Nobody will notice a saving of 1-2 bytes, but if we are talking about large amounts of data, these bytes can result in very real megabytes. Secondly, a reasonable choice of data types allows you to avoid some errors, both on the part of the programmer (at the stage of creating the program) and on the part of the user (while using the program).

    Simple data types - overview

    Simple data types are called simple because they do not contain any other types within them. In addition, simple data types ensure that only one value is stored in memory. Simple data types include the following:

    • integer;
    • real;
    • logical;
    • string (character).

    It should be noted that all of these types, with the exception of real, are ordered. What does it mean? This means that within this type, the values ​​are not arranged in random order, but in ascending order. Knowing this, in some cases you can eliminate unnecessary code in your program. Let me explain with an example exactly how the values ​​in these data types are ordered:

    Integer type - contains numeric values, integers. The numbers are ordered in ascending order: ..., -2, -1, 0, 1, 2, 3, ...
    Boolean type - contains only 2 values ​​- True, False, which are also ordered: False, True (follows from the correspondence False - 0, True - 1).
    Character type - characters from the code table. Since each symbol has its own code, the symbols are arranged in order of increasing code. For example, the letters of the Latin alphabet A, B, C, D, ... appear in the code table exactly like this, because The further from the beginning of the alphabet, the higher the code the letter has. The same applies to Arabic numbers in the code table - they go in order: 0, 1, 2, ..., 8, 9. This allows comparisons such as "A"< "Z" (this is true).

    Since the listed data types are ordered, it follows that all values ​​form a finite sequence. This corresponds to our ideas about data types - they all have their limitations. For example, there is no numeric data type that allows you to store an arbitrarily large number. There are “large” types, but they cannot store “number” “infinity”.

    Functions and procedures for ordinal data types

    There are several useful functions and procedures, without which it is sometimes difficult to operate with ordinal data types:

    Pred() - the function returns the previous value for the expression specified as the only argument.

    Examples: Pred(5) = 4, Pred("E") = "D", Pred(True) = False.

    Succ() is the inverse function of Pred() and returns the next value.

    Examples: Succ(5) = 6, Succ("E") = "F", Succ(False) = True.

    Ord() - returns the ordinal number of a value in a list of data type values. We have already encountered this function when working with strings - with its help we recognized the character code.

    Examples: Ord("A") = 65, Ord(True) = 1.

    Low() - returns the minimum value of the specified data type.

    Examples: Low(Byte) = 0, Low(Boolean) = False, Low(Char) = #0 (character with code 0).

    High() - returns the maximum value of the specified data type.

    Examples: High(Byte) = 255, High(Boolean) = True, High(Char) = #255 (in the Russian locale this is the character “ya”).

    Well, and two more procedures that we are already familiar with:

    Dec() - decreases the value by one.

    Inc() - increases the value by one.

    Don't forget about the second optional parameter of these procedures.

    Custom Data Types

    Based on ordinal data types, the programmer can create his own types - enumerable and interval. They will be discussed below.

    Integer types

    As the name suggests, integer types allow you to store integer numbers. Among them, there are types that store signed numbers (i.e., positive or negative), and there are also those that store only positive ones. The more values ​​a type can contain, the more memory it takes up. Let's look at integer data types.

    First let's look at unsigned types, i.e. those that allow you to store only positive numbers and zero:

    Byte - values 0..255 - occupies memory 1 byte.

    Word - meanings 0..65535 - 2 byte.

    LongWord - meanings 0..4294967295 - 4 byte.

    Now signed types (negative numbers are written with a minus sign "-" in front, non-negative numbers can be written with or without a "+" sign):

    ShortInt - values -128..127 - 1 byte.

    SmallInt - values -32768..32767 - 2 byte.

    LongInt - values -2147483648..2147483647 - 4 byte.

    Int64 - values -2 ^53 ..2 ^53 -1 - 8 byte.

    There are also 2 general types, which are reflected in the above. It is recommended to use these types, because... the compiler is “tailored” for them and creates faster and more efficient code:

    Integer - values -2147483648..2147483647 - 4 byte.

    Cardinal - meanings 0..4294967295 - 4 byte.

    It should be noted that integers can be represented not only in decimal, but also in hexadecimal number systems, i.e. in the form $xxxxxxxx, where x is one of the symbols 0, 1, ..., 8, 9, A, B, ..., E, F. For example, all colors (more precisely, their codes) are represented in the form hexadecimal numbers.

    Boolean types

    We are already familiar with logical expressions and the logical data type - this is the Boolean type, which takes values True And False. In addition to Boolean, the following logical types exist: ByteBool, WordBool and LongBool. However, the latter were introduced only to ensure compatibility with other languages ​​and programming systems. It is recommended to use only the Boolean type. A Boolean value occupies 1 byte in memory. In fact, of course, one bit is enough, but, unfortunately, we cannot operate on cells smaller than a byte.

    Character types

    Character types provide storage for individual characters. The main data type is Char, which contains characters with codes 0..255 . There are also types AnsiChar and WideChar. Type AnsiChar equivalent to type Char, i.e. they are essentially the same type. Occupies memory 1 byte. The code used to encode characters is ANSI (American National Standards Institute). Type WideChar encoded by international code Unicode and occupies memory 2 byte. The Unicode table includes characters from almost all languages ​​of the world.

    Real types

    From the name it follows that these types are used to store real values, i.e. real numbers. They differ in the limits of permissible values ​​and accuracy, i.e. number of digits after the decimal point. These are the types:

    Real (aka Double) - values ​​from 5.0x10^-324 to 1.7x10 ^308, accuracy - 15-16 numbers, occupies memory 8 byte.

    Real48 - values ​​from 2.9x10^-39 to 1.7x10^38, accuracy - 11-12 numbers, 6 byte of memory.

    Single - values ​​from 1.7x10^-45 to 3.4x10^38, accuracy - 7-8 numbers, 4 byte.

    Extended - from 3.6x10^-4951 to 1.1x10 ^4932, accuracy - 19-20 numbers, 10 byte of memory.

    Comp - from -2x10 ^63 +1 to 2x10^63 -1, accuracy - 19-20 numbers, 8 byte.

    Currency - from -922337203685477.5808 to 922337203685477.5807 , accuracy - 19-20 digits, occupies memory 8 byte.

    As with integers, real numbers can be preceded by a "+" or "-" sign.

    There are 2 forms of writing real numbers - with fixed point and with floating.

    Fixed-point notation is a regular notation in which the integer and decimal parts are separated by a period/comma.

    Floating-point notation involves writing the order of a number, which is separated from the number itself by the letter "E" (notation "e" is also acceptable). For example, record 1.5e2 means the number 1.5 with order +2, i.e. that's 1.5x10^2 = 150.

    Types Comp And Currency were introduced specifically for making accurate cash payments. At the same time, type Comp, as can be seen from the range boundary values, stores integers, so when given numbers with a fractional part, they are automatically converted to the nearest integer.

    Enumerable data types

    From considering ready-made data types, let's move on to types that can be created by the programmer himself. One option, as noted above, is an enum type.

    The point of an enumerated type is that we explicitly specify (enumerate) all possible values. The advantages are that, in addition to the given values, variables of this type will not be able to take any more values. In addition, meanings can be set that are quite meaningful - for example words. This will make it easier to understand the code and write the program.

    Data type values ​​are listed separated by commas, and the entire set is enclosed in parentheses. The type description must be made in a special section of the descriptions section - the type description section. This section is preceded by the type keyword. Those. the recording is approximately the same as the description of variables or constants, only instead of var And const is written type. The type itself is described as follows: the name of the type, then the equal sign and then the value itself. In the case of an enumerated type, this will be the set of possible values.

    Note: Almost all data types in Object Pascal are usually named with the letter "T" (short for "Type"). This is not a law of language - just one of the rules of good manners. Knowing that "T***" is a type, you will never be mistaken, otherwise the name can be confused, for example, with the name of a variable.

    Let's say we want to set a data type that defines one of the months of the year. We can describe it like this:

    type TMonth = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec ) ; var M: TMonth; (...) M:=Jun;

    Please note that after the declaration of an enumerated type, the program cannot contain variables whose name matches the name of the values ​​of the declared type. In our example, there cannot be variables "Jan", "Feb", etc. If you try to assign a variable of an enumerated type to a value not specified in the list, the compiler will throw an error, so it is not possible to make a mistake.

    The type section exists as a module of the entire form (this section initially describes the form itself: TForm1 = class(TForm) ...), and in any subroutine. The scope of a type is, accordingly, determined by the place in the program in which it is described.

    Interval data types

    Interval data types (also called bounded data types) are derived from existing types by restricting the range of values. The interval is specified by two constants - the initial and final boundaries. Each time a value is assigned to a variable, a check is made to ensure that the new value falls within the specified range. If the value does not fall within the range, an error message is generated. During program execution, specifying an invalid value does not result in an error, but the value of the variable may become incorrect.
    A restricted data type can only be created from a simple ordered type. The value of the second constant (i.e. the right border) must be greater than the value of the first (left border).
    Restricted data types are also described in section type. The recording format is similar, only two dots are placed between the boundary constants.

    For example, we want to work with dates in the program. You can create limited data types for day, month, and year values ​​(the range for the year value should be set depending on the task context):

    type TDay = 1 ..31 ; TMonth = 1 ..12 ; TYear = 1900 ..2100 ;

    Remember that using a limited data type will not reduce the memory footprint. This follows from the fact that setting an interval is just a conditional setting of possible values ​​from the general set of values ​​of a given type.

    Conclusion

    Today we looked at simple data types - integer, real, character and logical, and also learned how to create enumerated and interval data types in our programs. As noted at the beginning, all of these types allow you to store only one value and do not contain other types within them. Later we will move on to consider structural data types, where the situation is different.

    a - Latin) - only the article address (URL);
    ((article:122))- a full HTML link to the article (the link text is the title of the article).

    The built-in data types in the Delphi language include integer, real, characters, strings, pointers, and boolean types.

    Ordinal types. Ordinal types are those in which the values ​​are ordered, and for each of them you can specify a previous and subsequent value.

    Structural types. Structural types include sets, arrays, records, files, classes, and interfaces.

    Integer data types. In variables of integer types, information is represented in the form of integers, i.e. numbers without a fractional part.

    Table 1 Operations on ordinal types

    Operation

    Description

    Minimum value of ordinal type T

    Maximum value of ordinal type T

    The ordinal number of the value of the ordinal type expression. For an entire expression, simply its meaning. For other ordinal types, Ord returns the physical representation of the expression's result, treated as an integer. The return value is always one of the integer types

    The previous value in order. For integer expressions it is equivalent to X-1

    The next value in order. For integer expressions it is equivalent to X+1

    Decreases the value of a variable by 1. Equivalent to V:= Pred(V)

    Increments the value of a variable by 1. Equivalent to V:= Succ(V)

    Table 2

    Range of values

    2147483648 -- 2147483647

    8 bits, unsigned

    16 bits, unsigned

    32 bits, unsigned

    There is also a type called Integer, which is equivalent to the LongInt type. Its range is from -2147483648 to 21474836478. It occupies 4 bytes in memory. The main ones are Integer and Cardinal, so in most cases it is desirable to use these types.

    All operations defined for ordinal types are performed on integer data. Operations on integer types:

    Table 3

    Valid data types. Variables of real types contain numbers consisting of an integer and a fractional part.

    Table 4

    The main type that provides maximum performance is the Real type, which is currently equivalent to the Double type.

    Table 5 Functions of real types

    Return value

    Absolute value x

    Arctangent x

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

    Exponential function of x

    Fractional part x

    Whole part x. Despite the name, it returns a real (floating point) value, i.e. just sets the fractional part to zero

    Natural logarithm of x

    Pi number (3.1416...)

    The closest integer value to x. Returns an integer value. The "closest to x" condition does not work if the top and bottom values ​​are equidistant (for example, if the fractional part is exactly 0.5). In these cases, Delphi defers the decision to the operating system. Typically, Intel processors solve this problem by following the IEEE recommendation to round to the nearest even integer. This approach is sometimes called "banker's rounding"

    Square x, i.e. X*X

    Square root of x

    Whole part x. Unlike Int, which returns

    Character data types. Character types are designed to store a single character.

    Table 6

    Boolean data types. Boolean data type variables represent Boolean values, such as true and false.

    Table 7 Dimensions of variables of Boolean types

    2 bytes (Word capacity)

    4 bytes (Longint capacity)

    An array is a data structure that is a collection of variables of the same type that have a common name. Arrays are convenient to use for storing information that is homogeneous in nature, for example, tables and lists.

    Array Declaration

    An array, like any program variable, must be declared in the variable declaration section before use. In general, the array declaration instruction looks like this:

    Name: [lower_index..upper_index] of type

    where: name is the name of the array;

    array is a Delphi reserved word indicating that the declared name is the name of an array;

    lower_index and upper_index are integer constants that determine the range of changes in the index of the array elements and, implicitly, the number of elements (size) of the array;

    type -- type of array elements.

    What they don’t write about in Delphi books Grigoriev A.B.

    3.2.2. Delphi Real Types

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

    The sign is always one bit. It is equal to zero for positive numbers and one for negative ones. As for the sizes of the mantissa and exponent, this is where the difference between the types lies.

    Before moving on to specific numbers, let’s take a closer look at the Real type, making a short excursion into history. Real is a standard type of the Pascal language that was present there initially. When Pascal was created, processors did not yet have built-in support for real numbers, so all operations with Real data were reduced to operations with integers. Accordingly, the size of the fields in the Real type was chosen to optimize these operations.

    a) general form of a real number

    b) Binary representation of a number of type Single

    Rice. 3.1. Storing a real number in memory

    The Intel 8086/88 microprocessor and its improved variants - 80286 and 80386 - also did not have hardware support for real numbers. But systems based on these processors had the ability to connect a so-called coprocessor. This chip worked with memory through the buses of the main processor and provided hardware support for real numbers. In mid-range systems, the coprocessor slot was usually empty, since this reduced the price (of course, inserting a coprocessor there was not a problem). Each central processor had its own coprocessors, labeled Intel 8087, 80287 and 80387, respectively. There were even coprocessors produced by other companies. They were faster than Intel coprocessors, but appeared on the market later. The real number type supported by coprocessors is not the same as Real . It is defined by the IEEE (Institute of Electrical and Electronics Engineers) standard.

    To support IEEE types in its systems, Borland introduces the Single, Double, and Extended types into Turbo Pascal. Extended is the main type for the coprocessor, and Single and Double are obtained from it by very simple truncation. The coprocessor instruction system allows working with these types: when loading a number of type Single or Double into the internal register of the coprocessor, the latter converts them to Extended. On the contrary, when loading numbers of these types from a register into memory, the coprocessor truncates them to the required size. Internal operations are always performed with data of the Extended type (however, there is an exception to this rule, which we will discuss later, after a detailed discussion of the format of various types). Single and Double allow you to save memory. Neither of them are the same as the Real type. In systems with coprocessors, new types are processed noticeably (2–3 times) faster than Real (this takes into account the fact that the Real type, after appropriate conversion, was also processed by the coprocessor; if we compare the processing of the Extended type on a machine with a coprocessor and Real on a machine without coprocessor, then in individual operations a difference in speed of about 100 times was achieved). So that programs with these types can be executed on systems without a coprocessor, it was possible to connect a software coprocessor emulator to them. The emulator's processing of these types was slower than Real's processing.

    Starting with the 486 series, Intel is heading towards integrating the processor and coprocessor into one chip. The percentage of defects in microcircuits is too high, so Intel resorts to a trick: if a microcircuit is defective only in the coprocessor part, then jumpers are burned on this chip that block the coprocessor, and the microcircuit is sold as an 80486SX processor, which does not have a built-in coprocessor (unlike the full version, which was called 80486DX). There were also the opposite situations, when the coprocessor was not damaged, but the processor was inoperable. Such microcircuits were turned into an “80487 coprocessor”. But this is already exotic, and, according to the information we have, such a coprocessor has not reached Russia.

    The Pentium processor in all its variants had a built-in floating point unit (FPU - Floating Point Unit), and did not require a separate coprocessor. Thus, with the arrival of this processor, the Real type remained only for backward compatibility, and the Single, Double and Extended types came to the fore. Starting with Delphi 4, the Real type becomes synonymous with the Double type, and the old 6-byte type is called Real48.

    Note

    There is a compiler directive ($REALCOMPATIBILITY ON/OFF) that when enabled (it is disabled by default) makes Real a synonym for Real48 rather than Double.

    The field sizes for various real types are shown in Table. 3.1.

    Table 3.1. Field sizes in real types

    Type Type size, bytes Mantissa size, bits Exponent 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 precision, can be found in the Delphi help.

    From the book The C# 2005 Programming Language and the .NET 2.0 Platform. by Troelsen Andrew

    Value Types, Reference Types, and the Assignment Operator Now examine the following Main() method and look at its output, shown in Figure 1. 3.12.static void Main(string args) ( Console.WriteLine("*** Value Types / Reference Types ***"); Console.WriteLine(-› Creating p1"); MyPoint

    From the book Tips for Delphi. Version 1.0.6 author Ozerov Valentin

    Value Types and Containing Reference Types Now that you understand the difference between value types and reference types, let's look at a more complex example. Suppose we have the following reference type (class),

    From the book Internet Solutions from Dr. Bob by Swart Bob

    Value Types and Reference Types: Final Notes To complete our discussion of this topic, review the information in Table 1. Table 3.8 provides a summary of the main differences between value types and reference types. Table

    From the Delphi book. Tricks and effects author Chirtik Alexander Anatolievich

    From the book Fundamental Algorithms and Data Structures in Delphi author Bucknell Julian M.

    1.3.3. Delphi and CGI In this chapter, I will tell you how to write a simple Delphi CGI application, without using Web Modules or other Client/Server modules. Firstly, the abbreviation CGI stands for Common Gateway Interface, and it is just a name for transferring information from the client to the server. On the client side this is

    From the book InterBase World. Architecture, administration and development of database applications in InterBase/FireBird/Yaffil author Kovyazin Alexey Nikolaevich

    2.1.1. Delphi and HTML My main developer tool is Delphi, and we will write Delphi Database HTML Expert in this chapter. Delphi allows you to connect to almost any database format. Using BDE to Paradox and dBASE, using ODBC for example to Access, and using SQL Links to large DBMS type

    From the book Delphi Virtual Library by the author

    9.3. Using OLE in Delphi Like many modern programming environments, Delphi supports the possibility of automated development of applications that work with various COM services or servers. For a deeper understanding of how applications work,

    From the book Description of the PascalABC.NET language author RuBoard Team

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

    From the book ABC PASCAL Programming Language author Tsvetkov Alexander Stanislavovich

    Real data types Real types (also called floating point types) include FLOAT and DOUBLE PRECISION. The reader should immediately be warned against using the FLOAT type - its precision is insufficient to store most fractional values. Especially not

    From the author's book

    Questions about Delphi 2.0 What's new in Delphi 2.0 compared to Delphi 1.0? Released in February 1995, Delphi 1.0 was the first tool for Windows to combine an optimizing compiler, Two-Way-Tools visual development engines, and a scalable database processing architecture.

    From the author's book

    What's new in Delphi 2.0 compared to Delphi 1.0? Released in February 1995, Delphi 1.0 was the first tool for Windows to combine an optimizing compiler, Two-Way-Tools visual development engines, and a scalable database processing architecture. Today there are hundreds

    From the author's book

    From the author's book

    From the author's book

    Real types Below is a table of real types containing their size, number of significant digits and range of valid values: Type Size, byte Number of significant digits Value range real 8 15-16 -1.8?10308 .. 1.8?10308 double 8 15-16 -1.8 ?10308..

    The text of a Delphi program is formed using letters, numbers and special characters. The letters are the uppercase and lowercase characters of the Latin alphabet and the underscore: 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 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 _ Numbers are represented in standard Arabic notation: 0 1 2 3 4 5 6 7 8 9 Special characters + - * / = , . : ; " () ( ) @ # $ & ^ are used mainly as signs of arithmetic operations, separators, delimiters, etc. Composite characters are formed from special characters: =. . (. .) (* *) // : = They serve, in particular, to indicate operations such as “not equal”, “greater than or equal”, indicating ranges of values, commenting on a program, etc. Alphabet

    The same number can be written in many different ways, for example: 15 (integer) 15.0 (fixed-point real) 1.5 E 01 (floating-point real) $F (hexadecimal) Delphi allows you to use all the ways records, but most often use integer and real numbers. Integers consist only of digits and a + or – sign. If the sign is omitted and the number is not 0, then it is treated as positive, for example: 0 (0 is interpreted as an integer) 17 (positive integer) -39 (negative integer) Numeric data types

    Real numbers contain an integer and a fractional part, separated by a dot: 0. 0 (0 is interpreted as a real number) 133. 5 (a positive real number) -0. 7 (negative real number) Real numbers can be represented in two forms: fixed-point and floating-point. The fixed-point form is the same as the usual notation for numbers: 27800 (the period at the end of the number is omitted) 3. 14 The floating-point form (scientific form) is used when working with very large or very small numbers. In this form, the number before the E is multiplied by 10 to the power after the 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 = 3. 14) The number before the letter E is called the mantissa, and the number after the letter E is the exponent. Numeric data types

    Using comments, you can explain the logic of your program. The comment is ignored by the compiler and can be located anywhere in the program. A comment is: ( Any text in curly braces) (* Any text in parentheses with asterisks *) // Any text from a double slash to the end of the line If the characters ( or ( * are immediately followed by a dollar sign $, then the text in brackets is not considered a comment, but a compiler directive. Examples of such directives: ($OPTIMIZATION ON) ($WARNINGS ON) ($RANGECHECKS OFF) Comments

    A program always processes some data during execution. Data can be integer and fractional numbers, characters, strings, arrays, sets, etc. So a computer is just a machine for which data is a sequence of zeros and ones; it must absolutely “know” how to interpret them. For this reason, all data in Delphi is divided into types. The data type indicates what values ​​the data takes and what operations can be performed on it. Each data type corresponds to a certain amount of memory that is required to accommodate the data. For example, in the Delphi language there is a Byte data type. Data of this type takes values ​​in the integer range from 0 to 255, can participate in the operations of addition, subtraction, multiplication, division, and takes up 1 byte of memory. Data Types

    All data types in the Delphi language can be classified as follows: simple data types. They, in turn, are divided into ordinal and real data types. Ordinal types include integer, character, Boolean, enumerated, and other types; temporary data type. Used to represent date and time values; string data types. Serve to represent sequences of characters, such as text; composite data types. They are formed on the basis of all other types. These include arrays, sets, records, files, classes, and class references; procedural data types. Allow you to manipulate procedures and functions as program data; pointer data types. These types of data store addresses of other data (lists, trees, etc.); a data type with a non-constant value type. Used to represent values ​​whose type is unknown in advance; it can be used to easily organize work with a list of different types of values; Classification of data types

    Let's consider the form of description of variables, constants and types. Description of types: type =; Description of the constants: Const: =; Description of variables: Var: ; Data Description Form

    An example of writing constants: const Delphi. Language = "Object Pascal"; Kylix. Language = Delphi. Language; Yard = 914.4; Foot = 304.8; Seconds. In. Minute = 60; Seconds. In. Hour = Seconds. In. Minute * 60; // Set the Seconds constant. In. Day = Seconds. In. Hour*24; // as an expression When declaring a constant, you can specify its type: Const Percent: Double = 0. 15; File. Name: string = "HELP. TXT"; Such constants are called typed; their main purpose is to declare constant values ​​of composite data types. Description of constants

    In addition to standard data types, the Delphi language supports programmer-defined types. A new data type is defined using the reserved word type, followed by a type identifier, an equal sign, and a description. For example, you can define a new type: type TUnicode = Wide. Char; TFloat = Double; TDirection = (North, South, East, West); It is easy to notice that the identifiers of the new types in the example begin with a capital letter T (the first letter of the word type). This programmer type convention is accepted by Delphi developers, but it is not strict. However, we recommend sticking with it, as it makes the source code of the program easier to understand. Description of types

    Integer type range Shortint Smallint Integer Longint Cardinal Int 64 Byte Word Longword -128. . 127 signed 8 -bit -32768. . 32767 signed 16 -bit -2147483648. . 2147483647 sign. 32-bit 0. . 4294967295 unsigned 64 -bit -263. . 263 -1 signed 64 -bit 0. . 255 unsigned 8 -bit 0. . 65535 unsigned 16 -bit 0. . 4294967295 unsigned 32 -bit format Simple data types

    type range value 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 digits Comp – 9223372036854775808. . 9223372036854775807 19–20 Currency – 922337203685477. 5808. . 922337203685477. 5807 19– 20 Real types byte 8 6 4 8 10 8 8

    Character types are used to describe data whose value is a letter, number, punctuation mark, or other symbols. There are two fundamental character data types: Ansi. Char and Wide. Char. They correspond to two different character encoding systems. Ansi data type. Char occupy one byte of memory and encode one of the 256 possible characters in the extended ANSI code table, while the data type is Wide. Char takes up two bytes of memory and encodes one of the 65536 characters in the Unicode code table. The Unicode character set is a double-byte character encoding standard. The first 256 characters of the Unicode table correspond to the ANSI table, so the data type is Ansi. Char can be thought of as a subset of Wide. Char Character type

    Fundamental data types: Data type Memory size (bytes) Ansi. Char 1 Wide. Char 2 General data type: Data type Memory size (bytes) Char 1 (but can become equivalent to wide) Boolean 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 the C and C++ languages. All boolean data types are compatible with each other. Character and logical data type

    Example. Description of constants and variables of character type. const ch_p=’a’; //character constants ch_l: char=’f’; ch_k: wide. Char=’ 5’; var ch_l: char; //character variable In the program, the values ​​of variables and constants of character types are enclosed in apostrophes (not to be confused with quotes!), for example: Symbol: = "A"; // Symbol is assigned the letter A Example of character data types

    Strings are a dynamic array of characters. String – length no more than 256 characters. Wide. String - longer than 256 characters. Information is considered a string if it is enclosed in single quotes: ‘Mary It Bread’ is a string “Mary It Bread” is not a string Example. Define a constant and a variable of string type. Const С_wether=’Cold...’; Var s 1: C_wether; s 2: string; String data type

    Enumerated type. An enumerated data type is a list of values ​​that a variable of that type can take. Each value is associated with an identifier used in the program to indicate this value. Example. type TColors = (red, white, blue); TMonth=(jnu, feb, mar, april, may, jun, jul, Agu, sep, oct, nov, dec); TDirection = (North, South, East, West); var Month: TMonth; Direction: TDirection; begin Direction: = North; end. Enumerated data type

    In fact, enum type value identifiers are actually integer constants. By default, the first constant is 0, the second is 1, etc. It is possible to explicitly assign a value to the identifier type TSize. Unit = (Byte = 1, Kilobyte = 1024 * Byte, Megabyte = Kilobyte * 1024, Gigabyte = Megabyte * 1024); The maximum capacity of an enumerated type is 65536 values, so the enumerated type actually defines some subset of the whole word type and can be considered as a compact declaration of a group of integer constants with values ​​0, 1, etc.

    Interval data types An interval data type is specified by two constants that limit the range of values ​​for variables of this type. Both constants must be one of the standard ordinal types (not real or string). Example: type TDigit = 0. . 9; digit = "0". . "9"; dig 2 = 48. . 57; var Digit: TDigit; month: 1. . 12; begin Digit: = 5; Digit: = 10; // Error! Out of range End; Interval or type-range.

    The difference between this way of creating a type and the usual way (without the word type) will appear when you study arrays, records, and classes. Let's jump ahead and give an example: type TType 1 = array of Integer; TType 2 = type TType 1; var A: TType 1; B: TType 2; begin B: = A; // Error! end. In the example, variables A and B are incompatible with each other due to the word type in the type declaration of TType 2. If variables A and B belong to simple data types, then 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. The phrase array of is intended to describe an array. After the word array, the boundaries of the array are written in square brackets, and after the word of - the type of array elements: Type TStates = array of string; TCoordinates = array of Integer; const Coordinates: TCoordinates = (10, 20, 5); ( 3 integers ) var States: TStates; ( 50 strings ) Symbols: array of Char; ( 81 characters - without type definition) To access an individual array element, you need to indicate its index in square brackets, for example Symbols: ='е'; Please note that initialization of array elements occurs in parentheses separated by commas. Arrays

    The arrays declared above are one-dimensional because they have only one index. One-dimensional arrays are typically used to represent a linear sequence of elements. If two indices are specified when describing an array, the array is called two-dimensional; if there are n indices, it is called n-dimensional. Two-dimensional arrays are used to represent a table, and n-dimensional arrays are used to represent spaces. Here is an example of a table declaration consisting of 5 columns and 20 rows: var Table: array of array of Double; The same thing can be written in a more compact form: var Table: array of Double; To access an individual element of a multidimensional array, you need to specify the value of each index, for example Table or in the more compact notation Multidimensional arrays Table

    Example. Description of a two-dimensional dynamic array of byte type elements in the con variable. var con: array of byte; Example. Multidimensional arrays. var Mbon: array of byte; //four-dimensional Type Tmy_mas= 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 array Mbon - array element Mbon Mbon 1 - array element Mbon 1 C - // first element of a dynamic array Examples of dynamic arrays

    A set is a composite data type for representing a collection of some elements as a whole. The range of a set is a set of all possible subsets made up of its elements. All elements of the set must belong to a one-byte ordinal type - the base type. To describe a plural type, the phrase set of is used, after which the base type of the set is written: type TLetters = set of "A". . "Z"; var Letters: TLetters; Symbols: set of Char; In expressions, the values ​​of set elements are indicated in square brackets: , , ["A", "B", "C"]. If a set has no elements, it is called empty: . Example: const Vowels: TLetters = ["A", "E", "I", "O", "U"]; Begin Letters: = ["A", "B", "C"]; Symbols: = ; (empty set) End. The number of elements of a set is called cardinality. The cardinality of a set in the Delphi language cannot exceed 256. Sets

    Src="https://site/presentation/20070619_133096976/image-25.jpg" alt="When working with sets, it is allowed to use relational operations (=, , >=, When working with sets, it is allowed to use relational operations ( =, >=,). Two sets are considered equal if they consist of the same elements. The order of the elements in the sets being compared does not matter. Two sets A and B are considered unequal if they differ in cardinality or value. at least one element. Expression Result True = True = True = True Membership operations (>=, = B is True if all elements of set B are contained in set A. Expression A

    Operation in. Used to check whether an element belongs to a specified set. Typically used in conditional statements. 5 in = True 5 in = False The in operation allows you to perform complex condition tests efficiently and visually, sometimes replacing dozens of other operations. For example, the operator if (X = 1) or (X = 2) or (X = 3) or (X = 5) or (X = 7) then can be replaced with a shorter one: if X in then The in operator is sometimes written with negation : X not in S. This entry is erroneous, since two operations follow in a row. The correct notation is: not (X in S). Occurrence operation in

    Union of sets (+). The union of two sets is a third set containing elements of both sets. + = + = Intersection of sets (*). The intersection of two sets is a third set that contains elements that are simultaneously in both sets. * = * = Set difference (–). The difference between two sets is the third set, which contains elements of the first set that are not included in the second set. – = – = Two standard procedures Include and Exclude have been introduced into the Delphi language, which are designed to work with sets. The Include(S, I) procedure includes the element I in the set S. The Exclude(S, I) procedure excludes the element I from the set S. They duplicate the –/+ operation with the only difference that they work with one element and do it more efficiently. Union, intersection, difference