Last Updated:

Data Types in Delphi

delphi programming

 

Each programming language has differences in data. They can be completely different in one way or another. Just not everyone understands these differences. And therefore, during certain operations, difficulties may arise due to lack of knowledge. With Delphi, it is necessary to know the difference in data types, which means that it is necessary to resort to the material devoted to them.

Delphi language. Variables and constants

 

But before proceeding to the study of data types, it is worth paying attention to an equally mandatory topic for study. It concerns variables, constants, their appearance, and so on. Without this, it will be difficult to perform certain operations, because the user will not understand how the language works and what commands for the elements there are. Just in this paragraph it will be analyzed that there are variables, constants, as well as additional material on such a topic.

To describe the data, you must first enter the descriptions. This is specified outside the Begin and End blocks, because these are not commands to execute. Before the keyword called Implementation, the following structure is written:

var
Form1: TForm1;

And when such a part of the code is present, it is possible to declare all the elements that are required. These can be constants, variables, and other data. And the structure of such an action is as follows:

var variable_name : variable_type ;

However, there are times when one type of variable has several. In order not to repeat such a line of code each time for a separate data element, it is worth using a "shortening" command. And it looks like this:

var A, B, C : Integer;

Also, if you need to enter several descriptions in a row, you do not need to re-use Var. To do this, it is enough to apply the following structure, which looks like this:

var A, B : Integer;
C, D : String;

Now let's move on to constants. They are indicated directly by the user in the code. Here it is necessary to use, often, those meanings that are taken for those to which people are accustomed. For example, it is possible to take the number "Pi" as a constant. It can be designated in this way:

const pi=3.1415 ;
ZnakPi : String = 'This is the value of the number pi';

By the way, Delphi has a built-in constant called "Pi". And to use it as in the value of "3.1415...", you will have to apply its value using the variable Real. Or, directly in the expressions, it is necessary to use this so that the program "understands" what the user associates with "Pi".

That's it with variables and constants. Now you can move on to the data type, because this is an important topic that needs to be understood. Several types of information will be discussed. The first is whole, the second is symbolic, the third is string, and the last is logical. For each of them, important information will be highlighted in the paragraphs.

Delphi integer type

 

In the case of whole types, Delphi is simple. 7 pieces of such are supported here. These are Shortint, Smailint, Longint, Int64, Byte, Word, and Longword. Naturally, they all differ from each other in certain properties. For convenient understanding, a person is provided with this table with all the parameters of each whole type:

TypeRangeFormat
Shortint-128 — 1278 bit
Smailint-32768 – 3276716 bit
Longint— 2147483648 – 214748324732 bit
Int64-263 – 263 — 164 bit
Byte0 – 2558 bit, no characters
Word0 – 6553516-bit, no characters
Longword0 — 429496729532-bit, no characters

Also, it is worth noting the support of an additional type of Integer. It is equivalent to LongInt. And support is declared at Object Pascal.

Delphi character type

 

The character type in Delphi has a meaning that most users will guess. This is the output of characters to the printer or display. However, sometimes there may be a difference between the understandings of the "symbol". If we explain it in "scientific" language, then the symbolic type of data is needed to build a connection between memory areas with different volumes. Also, such a method can be used to perform a standard method of encoding or decoding information.

A character data type works with several formats developed by professional companies. The very first and "minimum", which was used in Pascal-ASCII and could exchange information with repositories that have an 8-bit data format. Then there was a new type, already called ANSI and there is one in the Delphi set. Eventually, the computer world then moved to a type of data exchange called UNICODE. It, after all, supports 16 bits.

In order for the user to be able to use several types of character data, he is provided with 2 types of physical data. They, just like that, have differences and are suitable for certain actions:

  • The first is AnsiChar. It works with single-byte characters ordered according to ANSI.
  • The second is WideChar. Here, interaction with characters that have a word length is already carried out.

The first 256 characters are the same as those presented in ANSI, but then there is a continuation, since UNICODE is used.

Delphi string type

 

A string data type supports several types of strings. That is, it can be short (ShortString), long (LongString), as well as wide (WideString). Users can use anything from the provided.

For compatibility with third-party programming languages, a string class with a finite zero can be used. As a rule, nothing special is needed for him. That is, reserved words as well as identifiers are not required. Everything works simply and without any additions.

It is worth clarifying the point about AnsiString and WideString. They are dynamically distributed data types. In view of this, their volume - length, depends solely on the amount of memory. The higher this value, the better and the user will be able to fit a huge amount of information without any problems.

The difference between AnsiString and WideString is that the former type writes data in Char format and the latter writes data in WideChar format. As a rule, AnsiString can often be suitable for users, since there is no need for great opportunities. And if you want to use any complex symbols, you should resort to WideString.

Delphi Boolean type

 

 

As with integer data types, there is more than one. The following declared types can be attributed to the class of Boolean types:

  • Boolean,
  • ByteBool,
  • WordBool,
  • LongBool.

All of them, as is customary in the topic, are different from each other. And what and what is the logical data type in general - this will be the conclusion point in this article.

Best suited for Boolean programming. The rest of the data types are required in order to better adapt the programming process to Windows. Therefore, we can say that only one variant of the logical data type is best provided to users.

The difference between all the proposed options is that they occupy a different amount of RAM. For example, Boolean, ByteBool occupy 1 byte, but already WordBool and LongBool-2 and 4, respectively. The accepted values in this case are True, which is "True" or False, "False".

Here's an example of using a Boolean data type in code with a variable declaration and a truth condition:

procedure TForm1.Button3Click(Sender: TObject);
var
i : integer;
prov : Boolean;
begin
i := 5;
prov := (i = 10);
if prov then
ShowMessage('The test was successful!')
else
ShowMessage('Validation failed!');
end.