Delphi is an Integrated Development Environment (IDE) for writing Object Pascal, an object-oriented variant of Pascal, applications for Windows, MacOS, Android, and iOS. Numerous predefined data types are available in Delphi, ranging from the simple ones like string to the compound ones like TPoint.
Simple Types of Data in Delphi
Data can be stored in a variety of ways in Delphi, just like in many modern languages. In this section, we’ll focus on simple forms. Defining a variable in Delphi is as follows:
var
LineTotal : Integer;
First,Second : String;
Your chosen name appears first, then a : and the type of variable. a ; marks the end of the line, as it does with all Delphi statements. As you can see, multiple variables of the same type can be defined in a single line.
Choosing a unique name for each variable is critical, and it also needs to be distinct from the Delphi language keywords to work properly. It’s worth mentioning that Delphi is case-insensitive. To achieve the best results, you’ll need a steady Delphi Oracle connection.
Number Types
For storing numbers, Delphi offers a wide variety of data types. Your decision will be based on how you intend to use the data. We could use Word, which has a line count of up to 65,535, as our Word Processor. Floating-point numbers may be required for financial or mathematical calculations.
var
// Integer data types :
Int1 : Byte;
Int2 : ShortInt;
Int3 : Word;
Int4 : SmallInt;
Int5 : LongWord;
Int6 : Cardinal;
Int7 : LongInt;
Int8 : Integer;
Int9 : Int64;
// Decimal data types :
Dec1 : Single;
Dec2 : Currency;
Dec3 : Double;
Dec4 : Extended;
More information about data types can be found here.
Text Data Types
One of the features of the Delphi programming language is the ability to store entire sentences as individual variables. These can be used to display, store user information, and more. Letters and sentences are stored in character variable types, such as Char, and words are stored in string variable types, such as String, in the same way.
var
Str1 : Char;
Str2 : WideChar;
Str3 : AnsiChar;
Str4 : ShortString;
Str5 : String;
Str6 : AnsiString;
Str7 : WideString;
Logical Data Types
Programming logic is used in conjunction with logical data types. They’re very straightforward:
var
Log1 : Boolean;
There are two types of enumerated variables: boolean variables and integer variables. A fixed number of values, designated by name, can be held by them. True or False values are allowed here.
Sets, Enumerations, and Subtypes
Code that makes use of sets and enumerations is simpler to understand and more reliable. The use of categories of data necessitates their use. When it comes to playing card suits, for instance, you may have an inventory. The suit names are spelled out in full detail. We must first define the enumeration values before we can have an enumerated variable. It can be done as follows:
type
TDocuments = (Reports, Memos, Letters, Whitepapers);
var
document : TDocument;
Enumerations are frequently mistaken for sets. It’s difficult to grasp the distinction. Only one of the enumerated values can be assigned to an enumeration variable. The set values can be none, one, some, or all. In this case, the set values are just indexed slots in a numeric range without any names attached to them.
Compound Delphi Data Types
Simple data types are comparable to single elements in a database or spreadsheet. Delphi provides a collection of compound data types, which consist of simple ones.
A set of variables can be grouped and treated as if they were a single variable. Maintaining an easy Delphi access ensures easy data management and operation.
1. Arrays
Indexes are used to access array collections. An array is a collection of numbered “slots” that hold data. Each slot contains a single piece of information. You can think of them as a series of lists. For instance:
var
Documents : array[1..4] of String;
begin
Documents[1] := ‘Reports’;
Documents[2] := ‘Memos’;
Documents[3] := ‘Letters’;
Documents[4] := ‘Whitepapers’;
end;
Indexes 1 to 4 are included in the array above (1..4). A range is indicated by the two dots on the graph. Delphi has been instructed to use string variables for the array elements. Integers or decimals could just as easily have been defined.
2. Records
Data is stored in records, which are similar to arrays in this respect. As a result, records can contain a variety of data formats. They are one of Delphi’s most useful and powerful features, setting it apart from many other programming languages.
In most cases, you’ll design your database schema. In other words, this is not a variable in and of itself. It is referred to as a type of data. Sections of type data are used to define it. For the sake of consistency, the record type is prefixed with a T. Here’s how we’d describe an Employee file:
type
TEmployee Record
firstName : string[20];
lastName : string[20];
age : byte;
end;
Take note of the [20] suffix on the strings. They’ll have a predetermined amount of room to work with. We need to tell Delphi that the length of a string is known so that it can create a record of that length. Keeping records of the same type in memory saves space.
Using this type of data, we can create a new record variable and assign to it:
var
employee : TEmployee;
begin
employee.firstName := ‘Sam’;
employee.lastName := ‘Smith’;
employee.age := 60;
end;
employee.firstName is now set to ‘Sam’
employee.lastName is now set to ‘Smith’
employee.age is now set to 60
Observe how the record elements are referred to without using an index in this example. Records are easy to work with because we refer to them by their element names, which are qualified with a dot.
3. Objects
A collection of data and logic is what makes up an object. They are similar to programs and data structures in their functionality. Delphi’s object-oriented design is based on these features.
Other types of data
After that, there are several different object types to choose from in Delphi.
1. Files
A file variable is a computer disk file’s identifier. Using file access routines, you can access these files. Files delve deep into the complexities of this subject.
2. Pointers
Pointers make it possible to refer to variables in an indirect manner.
3. Variants
They eliminate the need for the rigid type handling that comes standard with Delphi.
Conclusion
We have discussed the main Delphi data types, such as simple and compound ones. Good command of these data types ensures high productivity and easy data management.
Also read: How to Protect Your Data When Sending Files Online