Delphi is a proprietary development environment (IDE) for Pascal on Windows. It implements an object-oriented version of the language. The development environment is based on a graphical interface associated with the Delphi function source code editor. The programming language has gained popularity due to its ease of use in the development of graphical applications and database-related programs.
Arrays are the basis of programming
In 1995, Borland Software Corporation released Turbo Pascal's successor, Delphi, an integrated development environment that uses its own Object Pascal dialect to facilitate Windows applications. Compared to the IDE, Delphi features had unprecedented database support, creating a multi-dimensional environment that allows programmers to write code faster and with fewer errors than ever before.
The language was a universal tool for developing applications, including a code editor, a visual designer that supported cross-platform development, an integrated debugger, a control mechanism, and support for third-party plug-ins. The code editor offered developers new Delphi features: error analysis and refactoring.
Initially, the array in the Delphi program was static. This meant that its size should have been known at the time of writing the code.
In the fourth version, new Delphi functions were added to the language - dynamic arrays that varied in size. The developer did not need to declare the size when writing the code, and he could programmatically change it by creating a link, and, in fact, not allocating memory for the content.
In the latest version, before placing data, set the length using the convenient SetLength procedure. Now that the length is set, the values are assigned, in the same way as with the static array of the Delphi function. In this case, dynamic indexed by zero.
If during the work of the program you need to change the size - with static arrays this is simply impossible, but with dynamic arrays - it is easy to implement. To do this, call SetLength and use the newly selected elements in the array. After the size is resized, the original elements are still in it and no data will be lost.
Statistical and dynamic arrays
The static arrays of the Delphi function are actually just pointers to a contiguous region of memory that has been allocated to store the right amount of data. The compiler performs mathematical operations to turn the index into a pointer to one element in the array, while dynamic ones, on the other hand, add a level of indirection.
A dynamic array is a record containing information about it, including size, number of elements and a pointer to static. When SetLength is called, several processes occur:
- The size field is updated.
- The new (internal) static array of the Delphi 7 function is allocated with a new size.
- Elements of the old static are copied to the new.
- The static pointer changes to a new one.
If at the current position of the internal static array there is enough space for redistribution, and there is one variable that refers to the array, only step No. 1 occurs. All this is implemented each time its length is changed.
If there are other variables that reference the same array, the old static will not be deleted. Whenever the size of a dynamic array changes, it will be copied, which means enumeration in memory. The time it takes is proportional to size, for example, copying from 20 elements takes longer than from 10.
String operators
Like any programming language, in Delphi, variables serve as a placeholder used to store values. A variable containing a specific array of characters is declared of type String. Delphi has a quality assortment of string operators, functions, and procedures.
Before assigning String data to a variable, you need to know four string types. The short line of the Delphi function is Shortstring. This is a counted array (ASCII) of characters containing up to 255 characters per line. The first byte of this array stores the length. This principle of operation was fundamental in Delphi 1 (16-bit Delphi) and created a variable called small with a maximum length of 50 characters.
When a Short String variable is assigned a value, the string is truncated. Especially if it exceeds the maximum length of this type.
Variables and their type must be declared before use. The type of the variable must be selected so that it contains the variable:
- An integer is an integer, for example 42 or -5.
- Single or double - are used as a type with commas, for example, 3.3.
Operations can be applied to numeric variables:
- addition;
- subtraction;
- multiplication;
- module - can only be applied to an integer;
- char - used to contain one character, for example, m;
- string - used to contain sentences, for example, Hello world;
- Boolean values are True and False.
To combine 2 lines of characters, use the "+" operator. Example: Hello + world will be implemented as Hello world.
Variables and Constants
The parameter represents information and makes a call to the Delphi function in the procedure. A variable is a piece of data declared inside a function and is available exclusively in it. This local value is changed as required by the developer. There are global variables available throughout the dpr and project. They should be used only in exceptional cases.
When using a variable, it is declared in all files where it is used. Only variables passed as functions and procedures to Delphi are not declared in the one where they are applied. For the declaration, use the var keyword. They can be declared in .DPR or in .pas file procedures.
The TDBGrid Delphi component is one of the pearls of VCL. Designed to allow users to view and edit data in a grid, it provides various ways to customize how data is presented. For example, adding color to database grids will improve the appearance and differentiate the importance of certain rows or columns in the database.
Delphi files
Delphi consists of units, corresponding source files, and index cards (forms) that define graphical interfaces. A table of the various files that may need to be changed, as well as their purpose.
File extension | Description |
.Dcr | Project file |
.DFM | A drawing of a form containing properties of graphic components |
.dpr | The project file is the heart of the application, links all the various files containing the code (.pas) with .DPR to the Delphi date function |
.PAS | Source file containing application code |
.bdsproj | Project file associated with .DPR |
.RC | Windows Resource File |
Table of files generated after compilation.
File extension | Description |
.BPG | Project team file. |
.dcu | A file created at compile time, but not required. |
.dpk | The source package file. |
.dof | Project options file. |
.dsk | IDE preference. |
.RES | Windows resource file, it can contain icons, bitmaps, sounds. |
Pos function
The Delphi POS function returns an integer indicating the position of the first occurrence of one line in another. This is created as follows. Pos searches for the first full occurrence of the specified string. It is usually offered in single quotes in the source. The source is some variable.
If Pos finds a string, it returns the position of the character in Source, and the first character in Str, as an integer value, otherwise the Delphi function returns 0. String and Source will be strings. The old-fashioned Pos function is the most common search method and is always located at the beginning.
The updated Pos feature helps solve this problem. She searches for the line s1 in s2 and returns her position, as the old Pos does. In addition, you can determine the starting position and maximum length for the search.
Import library functions
To import library routines (.DLL), a directive is attached in the form: externalstringConstant, at the end of the header of functions and procedures, where string Constant is the name of the library file in quotation marks. It is possible to import a subroutine with a different name. To do this, indicate the original name in the external directive:
External stringConstant1, namestringConstant2.
Where the first string Constant indicates the name of the library file, and the second is the original name of the subroutine. The following statement imports the function from user32.dll. The initial function name is MessageBoxA. Instead of a name, you can use a number to identify the routine to import:
externalstringConstantindexintegerConstant.
Where integerConstant is the index of the routine in the export table.
The import declaration must follow the exact designation and register of the name of the subprogram. However, once the procedure is imported, there is no longer any difference between the two.
An example of creating a one-dimensional array
Let's say you need to form 3 one-dimensional arrays for 50 members of the software development community. The 1st array is the names, the 2nd is the email, and the 3rd is the number of downloads.
Any of them has indexes and a code to support all 3 lists synchronously. Naturally, you can try with one array. This requires strings of names and mail addresses, and an integer number of downloads.
For example, a subsequent declaration organizes a record type named REMember, which can be used in this case.
In fact, the design of the recording data has the ability to mix all kinds of integrated Delphi types, including those created. Records result in fixed collections of components of various types. Any element is similar to a variable from a name and type.
The Delphi Member function type covers 3 fields: the string value Name, eMail and the integer Posts. After the record type is set, you can declare the Member variable. It does not allocate memory for names, eMail and Posts. In order to practically create a Member record, declare its variable.
Using OnMouseOver Components
The code for the OnMouseMove events is created with the TDBGrid component so that you can find the rows and columns of DBGrid (cells) at the mouse cursor. If it is located above the grid, the OnMouseMove event handler fires. Then use the MoveBy method of the DataSet component to set the displayed current record.
Equivalent code is used to demonstrate the location of the mouse cursor and change it when it is located above the title bar. To correctly set the active record, you need to “crack” DBGrid and gain access to the protected Row property. The property lines of the TCustomDBGrid component contain a link to the current active lines.
Many components have useful properties and methods marked as invisible or protected by Delphi developers. Access to such elements is ensured by the use of a simple technique called “protected hacking”.
This code, when you hover over the grid, selects the entry displayed in the grid "under" the cursor. You do not need to click on the grid to modify an existing record. The OnDrawColumnCell event is used to handle the need for custom graphics for data in cells.
Skinning Delphi Applications
These components change the look of applications by adding themes and shells. This is an easy way to improve the graphical user interface (GUI). VCLSkin is an easy-to-use component for creating a graphical interface of a Delphi application. VCLSkin will create a theme or cover for it without any changes to the source code.
The DynamicSkinForm VCL library provides support for covers for forms, menus, tooltips, and many standard and custom original controls.
Skins have many objects and effects for cool applications such as WinAmp and iTunes. A special editor allows the user to customize skins. SkinAdapter is a DynamicSkinForm component that allows you to create application skins without changing the source code.
SUISkin offers an automatic application with skin support. With it, modifications to existing projects are not required. Simply drag the skin engine component onto the main shape and set some properties. It will automatically process all forms and dialogs. Skin files can be compiled into an exe file. At runtime, you can easily switch them on or off.
The App Face UI Development Kit is a solution for creating visual GUIs for applications that can be used in VC, VB.Net, Delphi, Visual Basic, C ++ Builder, and the Win32 SDK. It includes skin management, a tool for creating visual skins, source code examples, and a technical guide. The appface.dll library is a kernel component and can automatically process all created windows in the target application.
Programming Environment Benefits
Delphi, of course, has established itself as one of the most robust programming environments that change shape and size. Despite everything, it remains as flexible as the code base from which it came.
Reasons why they still use Delphi:
- Clear syntax that makes code as readable as possible.
- A drag-and-drop implementation engine that allows you to quickly create GUI software.
- SQL database support.
- Supports all Windows API.
- Full Object Oriented Programming.
- Compatible with C ++.
- Highly adaptable VCL environment.
- Minimum application maintenance required.
During its climax, a huge community developed a host of high-quality software products in the form of components with Delphi procedures and functions, many of which are completely free and open source. Today, all this still works, with only one problem - the lack of experienced Delphi programmers.