Delphi Interface Description. The best IT solutions for business. Default buttons

Object-oriented programming (OOP), in addition to the concept of class, also provides for the fundamental concept of the interface.

What is the interface and what are the features of working with him in the language programming Delphi.?

The interface is a semantic and syntactic design in the program code used to specify the services provided by the class or component (Wikipedia).

In essence, the interface determines the list of properties and methods to be used when working with a class that this interface implements, as well as their signature (name, data type, received parameters (for procedures and functions), etc.). Thus, a class that implements one or another interface must necessarily implement all its components. What is in strict accordance with how they are described in it.

Very often, the interfaces are compared with abstract classes, but with all the similarity, this comparison is not entirely correct. In abstract classes available, at least, management of visibility of members. At the same time, the visibility area interfaces are not defined.

Interfaces allow you to make architecture more flexible, as you will unify access to one or another functionality, and also avoid a number of problems associated with class inheritance (interfaces can also be inherited from each other).

To declare interface in Delphi, serves the keyword interface. This is the same Keyword that defines the module section to which it is possible to contact outside (between keywords Interface and Implementation). However, when an interface is declared, another syntax is used, similar to the classified classes.

Delphi / Pascal

IMYNEWINTERFACE \u003d INTERFACE PROCEDURE INTERFACEPROC; end;

IMYNEWINTERFACE \u003d INTERFACE.

procedure InterfaceProc;

end;

Thus, the syntax of the interface declaration itself does not have fundamental differences from other programming languages \u200b\u200b(the features of the Pascal based on Pascal is not counting). At the same time, the implementation of interfaces has a number of characteristic features.

The fact is that Delphi interfaces were initially entered to support COM technology. Therefore, the iINTERFACE interface, which in Delphi is a ancestor for all other interfaces (a kind of tobject analogue), already contains three basic methods for working with this technology: queryInterface, _Addref, _release. As a result, if the class implements any interface, then it must be implemented to implement these methods. Even if this class is not designed to work COM.

Due to this feature of the IINTERFACE interface, in Delphi, the use of interfaces, in most cases, leads to the addition of non-used capabilities to the class.

There is a library class TINTERFACEOBJECT, which already contains the implementation of these methods and, while inheritance from it, the need to implement them independently disappears. But since Delphi does not support the multiple inheritance of classes, its use often only causes additional difficulties in designing and implementing the required functional.

All this led to the fact that, despite all the possibilities provided by interfaces, their practical application in Delphi almost did not go beyond the work with COM.

Being optimized for work mainly with this technology, interfaces, and more accurately addable functionality and architectural restrictions, when solving other tasks, do not justify yourself.

Therefore, many Delphi programmers are still in fact devoid of a powerful and flexible tool for developing application architecture.

This is an article based on issues on the forums: "How can I return the line from DLL?", "How to transfer and return an array of records?", "How to transfer to the DLL form?".

In order for you not to spend half of life to figure out - in this article I will bring everything on a scenery.

The topics of this article in varying degrees have repeatedly affected this blog, but in this article they are collected in a bunch, justifications are given. In short, reference to this article can be thrown in those who develop DLL.

Important note: The article needs to be read sequence. Examples of code are given only as examples, at each step (paragraph) of the article, the code of examples is added with new details. For example, at the very beginning of the article, there is no error handling, "classic" methods (such as, using GetLastterror, SDTCALL agreements, etc.), which in the course of the article are replaced with more adequate. Made so for the reason that the "new" design ("unusual") designs did not cause questions. Otherwise, when I had to insert a note of the species to each example: "This is discussed at that point below, but what is this. In any case, at the end of the article there is a link to the ready-made code, written in the whole of what has been said in the article. You can just take it and use. And the article explains why and why. If you are not interested in "why and why", leaf at the end to the conclusion and link to download the example.

One and most strong Parties The Delphi programming environment is its open architecture, thanks to which Delphi allows a kind of metaprogramming, allowing you to program programming environment. This approach translates Delphi for qualitatively new level Application development systems and allows you to embed additional instrumental tools to this product that support almost all stages of creating applications. Such a wide range of features opens with the concept of so-called open interfaces implemented in Delphi, which are a link between IDE (Integrated Development Environment) and external tools.

This article is devoted to open Delphi interfaces and is an overview of their capabilities. Delphi defines six open interfaces: Tool Interface, Design Interface, Expert Interface, File Interface, Edit Interface and Version Control Interface. It is unlikely that, as part of this article, we would have managed to highlight in detail and illustrate the possibilities of each of them. More thoroughly understand the issues in question, the source texts of Delphi will help you, the benefit of the developers provided them with deployed comments. Announcements of classes representing open interfaces are contained in the corresponding modules in the directory ... \\ Delphi \\ Source \\ Toolsapi. Design Interface (DSgnTF.PAS module) provides tools for creating property editors and component editors.

Property editors and components are a topic worthy of a separate conversation, so we will only remind you that the property editor controls the behavior of the object inspector when trying to change the value of the corresponding property, and the component editor is activated by double the left mouse button on the image of the component placed on the form. Version Control Interface (VCSintF.PAS module) is designed to create versions control systems. Starting with version 2.0, Delphi supports an integrated system control system for Intersolv PVCS, so in most cases there is no need to develop your own system. For this reason, the review of Version Control Interface is also omitted. File Interface (FileIntf.PAS module) allows you to override the IDE working file system, which makes it possible to select your own file storage method (in Memo fields on the database server, for example). Edit Interface (EditintF.PAS module) provides access to the source text buffer, which allows you to analyze the code and execute it, to determine and change the cursor position in the code editor window, as well as manage the syntactic selection of source text.

Special classes provide interfaces to components placed on the form (determination of the component type, receiving references to parent and child components, access to properties, focus transmission, delete, etc.), to the most form and to the project resource file. EDIT Interface allows you to identify the so-called modular impressors that determine the reaction to events such as changing the source text of the module, modifying the form, rename component, saving, renaming or removing the module, changing the resource project file, etc. Tool Interface (Toolintf module. PAS) provides developers tools for obtaining general information on IDE status and perform such actions such as opening, saving and closing projects and individual files, creation of a module, receiving information about the current project (number of modules and forms, their names, etc.), registration file System, organization of interfaces to individual modules, etc. In addition to the Tool Interface modular notifications, it defines the ADD-IN impatients notifying such events as opening / closing files and projects, downloading and saving project Desktop file, add / exclude project modules, installation / degeneration packages, project compilation, and in The difference from the modular notifiers ADD-IN Books allow you to cancel the execution of certain events.

In addition, Tool Interface provides access to the main menu of IDE Delphi, allowing you to embed additional items. Expert Interface (ExptintF.PAS module) is a foundation for creating experts - software modules embedded in IDE to expand its functionality. As an example of an expert, you can bring in the Delphi Database Form Wizard that performs the generation of the form for viewing and changing the contents of the database table. Having determined the class of an expert, it is necessary to take care that Delphi "learned" about our expert. To do this, it needs to be registered by calling the RegisterLibraryExpert procedure by passing it as an instance of an expert class. As an illustration, we will create a simple ESstandard-style expert, which, when choosing the Delphi menu item that corresponds to it, displays a message that it is running. As can be seen from the above table, the Esstandard style obliges to overlap six methods:

In order for the expert to be "enabled", you need to select the Component / Install Component menu item, select a module in the Browse dialog, containing an expert (in our case EXMPL_01.PAS), click OK, and after compiling DCLUSR30.DPK package In the main menu, the Delphi section in the Help section should appear the item SIMPLE EXPERT 1, when you select the information message "Standard Expert Started!". Why Delphi places an expert menu item in the Help section, remains a mystery. If you do not like what the menu item appears where you want Delphi, and not where you want, the following option is possible: Create an Add-in style expert, which eliminates the automatic creation of the menu item, and the Add Manual menu item Using Tool Interface. This will allow you to set the location of the new item in the main menu randomly.

To add the menu item, the TitoolServices class is used - the Basis Tool Interface - and TimainMenuintf classes, TimenuiteMintf, implementing the interfaces to the Main Menu IDE and its items. TitoolServices class TitoolServices instance is created by the IDE itself when it is initialized. Please note that the responsibility for the release of interfaces to the main menu of Delphi and its items falls on the developer. In terms of the way, the functional load of the expert is slightly complicing: when you activate your menu item, it will give a certificate about the name of the project opened in this moment In Wednesday: In this example, the ADDIDIDIDIDIDEMENUIEM function is held, which exercises the menu item to the Main Menu of IDE Delphi. As parameters, it is transmitted to the text of the new menu item, its identifier, the item identifier, before which the new item is inserted, the symbolic key representation, which together with with the Ctrl key can be used for quick access To a new item, and an event handler corresponding to the selection of a new item. We added a new menu item to the View section in front of the Watches item.

Now let's get acquainted with the notifiers. We define the Add-in notifer, tracking moments of closing / opening projects and correcting the field accordingly that stores the name of the active project (implementation of methods that did not undergo changes compared to the TPred example, for brevity to lower): To implement a notifier, we defined the Taddinnnotifier class, which is a descendant Tiaddinnotifier, and blocked the FileNotification method. IDE will call this method every time an event occurs, which is capable of reacting AD-IN notifier (each such event is denoted by the corresponding TFILENTIFICATION type constant). The Expert field in the TaddinNotifier class serves for feedback with an expert (TADDINNOTFIER.FILENTIFICATION method). In the expert destructor, the registration of a notifier is removed, and the notifier is destroyed. And now we will illustrate the use of modular notifiers. Let us create an add-in expert that issues messages about each act of saving a project file (the implementation of already familiar methods for brevity is not cited): In this example, the Add-in expert monitors events that meet the opening / closing of projects.

Each time the project is discovered, a modular notifier corresponding to the project file is recorded. In terms of implementation, modular impressors are similar to ADD-IN Books: We define the TMODULENOTIFIER class, which is a descendant of Timodulenotifier and overlapping its Notify and Componentrenamed methods. IDE calls the Notify method in case of certain events related to this module; Inside this method, the reaction to a particular event is determined. The COMPONENTRENAMED method is called when changing the name of the component lying on the module form. Please note that we do not use this method, but they must block it, otherwise when changing the component name will be challenged with an abstract base class method, which leads to unpredictable consequences.

Registering a modular notifier is a somewhat more complex process compared to the registration of the ADD-IN of the notifier: first we get the module interface (TimoduleInterface), and then using the module interface, register a notifier. When the project is closed, the registration of a modular notifier is removed (again using TimoduleInterface), and the notifier is destroyed. In conclusion, we will show how you can define the cursor position in the code editor window. Create an expert that, when choosing the appropriate menu item, I would give a message containing the name of the active file and the cursor position in it (the implementation of only essential for this example methods): To determine the position of the cursor, we must get the following interface sequence: modular interface (timoduleInterface); Code Editor Interface (TieditorInterface); Module representation interface in the editor window (TieditView).

If, when you select the Expert menu item, the source file is active (* .PAS), then a message containing the name of the active file and the current position of the cursor in it is issued. If an active is not a PAS file, the message is not issued. To get the name of the active file, use the getCurrentFile method of the TitoolServices class. At this end, consideration of ways to use open interfaces. CD-ROM contains the source texts of all given examples. The CD-ROM also contains a more complex and detailed example containing the ADD-IN expert, allowing the user to bookmarks in the source text of Delphi modules. Summary The installation and use of the expert bookmarks is contained in the bkmrks97.htm file. So, in this article, open interfaces are considered in general terms and examples of their use are given. Once again we repeat: thanks to the presence of source texts of open interfaces, you can easily understand the details of interest to you. We hope that the diversity of opportunities provided by open interfaces, you have no one bold and useful idea.

Creature interface The user comes down to choosing from the component palette necessary for the Delphi component program, employees interface management as well interface Display information and transfer them to form followed by layout.

The user interface created by you must use the standard items familiar to users, and provide maximum convenience. All this ultimately is determined by such a criterion as the effectiveness of the interface - the maximum result with minimal effort.
The principles of creating a convenient interface are known. As the most general principles when creating user interfaces Three main provisions can be considered:

  1. The program should help perform the task, and not becoming this task.
  2. When working with the program, the user should not feel like a fool.
  3. The program should work so that the user does not consider the computer with a fool.
First principle - This is the so-called "transparency" of the interface. The user interface must be intuitive, simple for development, and not to create the user problems that it will have to overcome in the process of work. Use standard, without excessive decoration components, use the usual, used similar control programs, and you will achieve execution criteria first principle.

Second principle lies in neglect of user intellectual abilities. On the own experience I know that often users not only do not know how to work at the computer, but they are simply afraid to take something on their own. Therefore, the user interface must be as friendly as possible.
Moreover, the fears of users are often justified, because the cost of the program, and the computer itself does not go to any comparison with the cost, for example, created by long-term database efforts. That is why the programmer when creating an interface of the user must always be embedded in the program "protection from the fool" - from incorrect actions and input by the user of incorrect data. But some programmers are too fond of such protection, make it too annoying, and as a result, the work of the program resembles the famous "Step left, the step to the right is considered to be escape"! And the fact that the programmer creates as a solution to the problem itself begins to create problems.
For compliance second principle You do not need to allow the program to "correct" the actions of the user and indicate that exactly how to act, driving into a narrow frame. Also, it should not be overly carried away by the output of information messages-tips, especially dialogues, it distracts the user from work. And it is better to provide for the possibility of turning off the prompts.

Third principle It is to create a program with the highest possible "mental" abilities. Despite the rapid development of computer equipment, even widespread programs can only be very conventionally called having artificial intelligence. They interfere with the work of the user, displaying on the screen dialog boxes With stupid questions causing bewilderment even in the simplest situations. As a result, users in the hearts exclaim: "Well, the stupid one car"!
I personally cause irritation to constant questions from almost all text editors On whether the changed text is not to preserve, although the initial and current text do not differ in any symbol. Yes, I recruited something, but then I returned everything back, could you really not figure out! I have to check if I did not spoil anything.

Try to adhere to the following rules:

Standard interface elements
Use the standard component interface for this element. Having met your program, the user will not waste time acquaintance, and immediately starts work - this is one of the signs of a professionally made program.
Small palette of tools
Try to use not too a large number of A variety of components. And naturally, using somewhere in one place one standard component, in the same case also apply it.
Same distance between controls
Position the interface elements at the same distance between themselves. Scattered as components have created a feeling of a non-professionalized product made. Conversely, carefully verified placement on the form of buttons, switches, flags and other components that make up the interface - a sign of quality work.
Taborder. "Right" order
Taborder. - This is the procedure for moving the on-screen cursor by control elements when you press the key Tab.. In the correctly written program, the cursor moves, following the logic of the user's work with the program. When creating the program, the programmer often changes the components, one removes, others adds as needed. As a result, in the finished program, the cursor chaotically jumps in shape. After completing the program, do not forget to configure Taborder..
Selection of fonts
Fonts just leave alone alone. Default Delphi itself fonts are suitable for any system where your program can work. Separate font Use only to highlight important elements. Application kursiva and especially employingwhich user can accept the hyperlink - a bad tone.
Selection of flowers
As for the colors of the elements of the interface, then also, as in the case of fonts, it is better to leave them standard, by default. Delphi uses the Windows system palette, and the user by changing it will easily configure the colors for itself.
Alternative governance
A professionally made program should be able to control not only the mouse, but also from the keyboard. There should be no functions available to execute only with the mouse (drawing in graphic editors Do not count!). For the most used features, hotkeys should be provided for a quick call.
Bricks interface
As for the specific elements of the user invention, the quality of user interaction with the program depends on:
  • compliance of the control of the problem performed by them;
  • rules for which the control function functions.
    This page addresses the rules for creating some interface elements.
And now I want to show which tools offers Delphi to control the components on the form, their mutual location and cursor behavior when the key is pressed Tab..

In order to arrange the components relative to each other in the correct order, first it is necessary to allocate them. You can simply circle the area on the form in which the selected components are contained. Or holding " Shift.", Specify the same mouse to be allocated to the component. Repeated with the mouse over the dedicated component (pressing" Shift.") Removes it from it.

The dedicated components can be controlled as a single integer - to move in the form, assign the value to the same properties, copy (for installation, for example, to another form), even delete.

Now click right-click One of the components, and from the "pop-up" menu, select Position -\u003e Align ... A dialog box appears, which allows you to adjust the position of the components in the horizontal group and vertical group. For example, we need to align our four buttons on the left edge and make it so that between them the same vertical distance. To do this, highlight the radio channels Horizontal: Left Sides and Vertikal: Space Equally.

Selecting item Center, we are positioning the components so that their centers will be located on the same horizontal or vertical line, and item Center In Window. Moves the components to the center of the window, also horizontally or vertically.

In the same menu Row Tab. O.rDER ... Causes the appearance of the dialog box that controls the crossing of the cursor by the interface elements when the key is pressed Tab.. At the time of the form appear on the screen, the cursor will be, naturally, on the component located on the first line of the dialog box. And then it will move down the list. On the two blue arrow "up" and "down" dialog box, control the position of the selected component. Select the desired component, move the arrows to the desired line in the list, and so on.

When choosing a menu item Control -\u003e The submenu appears, consisting of two points:

  • Bring to Front
  • Send to Back.
These are component methods available also programmatically. Button1.sendToback Moves the button to "Back Plan", and Button1.BeringTofront. - bring to Front". That is, if one component is located above the other, these methods change them in places. Cases in which it can be used is quite obvious.

only for the result

hard observance of the deadlines

Transparency

project execution

technical supports as a gift

Programming, refinement of consulting on 1C

How we are working

1. Discuss the problem by phone. In the presence of remote access - Show on your computer screen.

2. We appreciate the work in rubles, if the project is big, if not, the approximate number of hours.

3. We do work.

4. You take a job in your program if there are shortcomings we correct them.

5. We exhibit the bill, you pay.

The cost of work

1. All works are divided into 3 categories: consultation, updating typical configuration, development or programming of a new report, processing, buttons, etc.

3. For more than 10 hours, the technical task describing and the cost of work is preliminarily drawn up. Works begin after agreeing the TK with you.

Technical support

1. If you find any errors in previously accepted works, within 3 months, we correct them for free.

2. Regular customers, any shortcomings made in our works, correct free of charge during the year.

Programs to manage your business.

Buy 1C: Enterprise

We are the official dealer of the company 1C, you can purchase various software products and licenses. In addition to buying a "box", we will help you configure the program, we will consult and make the basic settings.

  • Accounting
  • Store Automation
  • Wholesale
  • Assistance in installing and initial setting Included in the package!
  • Thin configuration configurations for the needs of the customer, the development of new modules in the absence of the necessary functions in the standard configuration.
1c accounting 1C: Managing Trade 1C: Retail 1C: Salary and Personnel Management
From 3300 rubles. From 6700 rubles. From 3300 rubles. From 7400 rubles.

Providing server.

Instant configuration Server + 1C.

No server? Do not trouble, pick up and quickly configure the server in the "cloud". For a small fee you get a very reliable solution.

  • Availability 24 \\ 7
  • No need to keep your own system administrator (Savings will cover the cost of your server).
  • Fast setting and installing 1C to the server, after 3 days you will already have a fully working system.
  • At any time you can move on local serverif the decision does not suit.

SMS from your 1c

Want to make customers during the promotions, discounts? Customers are not returned? Set up sending SMS. Right out of 1C!

Our company will be able to short time Configure send SMS to your customers directly from 1C. Examples of events that can automate:

  • Thanks for the purchase and accrual of bonuses immediately after another purchase.
  • Accrual bonuses on a card as a birthday party \\ to another significant or festive day.
  • Notice of goods receipt to the warehouse.
  • The expiration of gift bonuses.
  • Notification of the receipt of prepayment and reservation of goods.
  • Address with refinement to the store \\ Office, phone numbers.
  • Etc.

Setting in 1C can be made by our specialists or their employees. You can get acquainted with tariffs on the SMS tariffs page.

  • SMS delivery guarantee, money is removed only for delivered SMS.
  • Separate charification of each SMS.
  • Balance replenishment in different ways.
  • View the history of all sent SMS at any time.
  • Sender name instead of a digital number in the recipient's phone.

Top.