04.01.2021

Summary: Using open interfaces of the Delphi programming environment. Recommendations for creating user interfaces in Delphi Using interfaces in delphi


only for the result

strict adherence to deadlines

Transparency

project execution

technical support as a gift

Programming, revision of advice on 1C

How we are working

1. We discuss the problem over the phone. In the presence of remote access- show on your computer screen.

2. We estimate the work in rubles, if the project is large, if not - the approximate number of hours.

3. We get the job done.

4. You accept work in your program, if there are any shortcomings, we correct them.

5. We issue an invoice, you pay.

Cost of work

1. All work is divided into 3 categories: consultation, updating a typical configuration, developing or programming a new report, processing, buttons, etc.

3. For work more than 10 hours, a technical assignment with a description and cost of work is preliminarily drawn up. Work begins after agreeing on the terms of reference with you.

Technical support

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

2. For regular customers, we correct any shortcomings in our work free of charge throughout the year.

Programs to manage your business.

Buy 1C: Enterprise

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

  • Accounting
  • Store automation
  • Wholesale
  • Installation and initial setup help is included in the package!
  • Fine-tuning of configurations for the needs of the customer, development of new modules in the absence of the necessary functions in the standard configuration.
1c accounting 1C: Trade Management 1C: Retail 1C: Salary and Personnel Management
From 3300 rub. From 6700 rub. From 3300 rub. From 7400 rub.

Server provision.

Instant setup server + 1C.

Don't have a server? It doesn't matter, we'll pick up and quickly set up a 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(the savings will cover your server costs).
  • Quick setup and installation of 1C on the server, in 3 days you will already have a fully working system.
  • At any time, you can move to a local server if the solution does not suit you.

SMS from your 1C

Do you want customers to know about promotions, discounts on time? Customers not returning? Set up sending SMS directly from 1C!

Our company will be able to quickly set up sending SMS to your customers directly from 1C. Examples of events that can be automated:

  • Thanks for the purchase and the accrual of bonuses immediately after the next purchase.
  • Accrual of bonuses to the card as a gift for a birthday \ for another significant or holiday.
  • Notification of goods arrival at the warehouse.
  • Expiration of gift bonuses.
  • Notification of the receipt of an advance payment and reservation of goods.
  • Address with details of how to get to the store / office, phone numbers.
  • Etc.

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

  • SMS delivery guarantee, money is withdrawn only for delivered SMS.
  • Separate billing for each SMS.
  • Balance replenishment in different ways.
  • View the history of all sent SMS at any time.
  • The sender's name instead of the digital number in the message recipient's phone.

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

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

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

In fact, the interface defines a list of properties and methods that should be used when working with the class that implements this interface, as well as their signature (name, data type, accepted parameters (for procedures and functions), etc.). Thus, a class that implements a particular interface must necessarily implement all of its components. What does it have to do with strict compliance with the way they are described in it.

Interfaces are often compared with abstract classes, but despite the similarity, this comparison is not entirely correct. In abstract classes, at least control over the visibility of members is available. At the same time, no scopes are defined for interfaces.

Interfaces allow you to make the architecture more flexible, since they unify access to a particular functionality, and also allow you to avoid a number of problems associated with class inheritance (interfaces can also be inherited from one another).

To declare an interface in Delphi, use the interface keyword. This is the same keyword that defines the section of the module that can be accessed from outside (between keywords interface and implementation). However, when declaring an interface, a different syntax is used, similar to class declarations.

Delphi / Pascal

IMyNewInterface = interface procedure InterfaceProc; end;

IMyNewInterface = interface

procedure InterfaceProc;

end;

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

The point is that Delphi interfaces were originally introduced to support COM technology. Therefore, the IInterface interface, which in Delphi is the ancestor for all other interfaces (a kind of analogue of TObject), already contains three basic methods for working with this technology: QueryInterface, _AddRef, _Release. As a result, if a class implements any interface, then it must necessarily implement these methods as well. Even if this class is not designed to work with COM.

Due to this feature of the IInterface interface, in Delphi, the use of interfaces, in most cases, leads to the addition of deliberately unused capabilities to the class.

There is a library class TInterfaceObject, which already contains the implementation of these methods and, when inheriting from it, there is no need to implement them yourself. But since Delphi does not support multiple class inheritance, its use often only causes additional difficulties in the design and implementation of the already required functionality.

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

Optimized to work mainly with this technology, interfaces, or rather the functionality and architectural constraints they add without fail, do not justify themselves when solving other problems.

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

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

So that you don't waste half your life trying to figure it out, in this article I will bring everything on a silver platter.

The topics of this article have already been touched upon in this blog to varying degrees, but in this article they are collected in a bunch, the rationale is given. In short, a link to this article can be thrown at those who develop DLLs.

Important note: the article needs to be read consistently... Code examples are provided 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, the "classic" methods are indicated (such as using GetLastError, sdtcall conventions, etc.), which are replaced with more adequate ones in the course of the article. This is done for the reason that the "new" ("unusual") constructions do not raise any questions. Otherwise, for each example, it would be necessary to insert a note of the form: "this is discussed in that paragraph below, but this is in this one." In any case, at the end of the article there is a link to the ready-made code, written taking into account everything said in the article. You can just take it and use it. And the article explains why and why. If you are not interested in "why and why" - scroll down to the conclusion and the link to download the example.

I have a problem using Delphi class from C ++ code. delphi dll demo that exports a function that returns an object.
my Delphi Dll code looks like this:

Library DelphiTest; // uses part .... type IMyObject = interface procedure DoThis (n: Integer); function DoThat: PWideChar; end; TMyObject = class (TInterfacedObject, IMyObject) procedure DoThis (n: Integer); function DoThat: PChar; end; // TMyObject implementation go here ... procedure TMyObject.DoThis (n: Integer); begin showmessage ("you are calling the DoThis methode with" + intToStr (n) + "parameter"); end; function TMyObject.DoThat: PChar; begin showmessage ("you are calling the DoThat function"); Result: = Pchar ("Hello im Dothat"); end;

// export the DLL function:

Function CreateMyObject: IMyObject; stdcall; export; var txt: TextFile; begin AssignFile (txt, "C: \ log.log"); Reset (txt); Writeln (txt, "hello"); Result: = TMyObject.Create; end; exports CreateMyObject;

in my C ++ project, I have declared the IMyObject interface like this:

Class IMyObject (public: IMyObject (); virtual ~ IMyObject (); virtual void DoThis (int n) = 0; virtual char * DoThat () = 0;);

and my main function is like this:

Typedef IMyObject * (__stdcall * CreateFn) (); int main () (HMODULE hLib; hLib = LoadLibrary (L "DelphiTest.dll"); assert (hLib! = NULL); // pass !! CreateFn pfnCreate; pfnCreate = (CreateFn) GetProcAddress ((HINSTANCE) hLib, "CreateMyObject "); if (pfnCreate == NULL) (DWORD errc = GetLastError (); printf ("% u \ n ", errc); // it gets error 127) else (printf (" success load \ n ");) IMyObject * objptr = pfnCreate (); objptr-> DoThis (5); FreeLibrary (hLib); int in; scanf_s ("% i", & in); return 0;)

in this example, I got a runtime error when I try to access the exported function. errors in the line:
IMyObject * objptr = pfnCreate ();

Can you tell me what is wrong with my example.
and if possible any working example for accessing a Delphi class (in DLL) from C ++ code.

Solution

The first problem is calling the convention of methods. The Delphi interface uses register which is a Delphi specific calling convention. using stdcall For example, for interface methods.

The next problem is in C ++. Your C ++ interface must derive from IUnknown. Also, it must not declare a constructor or destructor.

Apart from this, your Delphi code is exported by PWideChar which does not map to char *, It maps to wchar_t *.

Looking further, returning PChar works great here because your implementation is returning a literal. But more serious code will probably want to use a dynamically allocated string, at which point your design is flawed.

Note that to create a file at the root system disk you must be an elevated administrator. So this is another potential point of failure.

I expect there are other errors, but this is all I have found so far.

One and the most strengths The Delphi programming environment is its open architecture, thanks to which Delphi allows a kind of metaprogramming, allowing you to “program the programming environment”. This approach takes Delphi to a qualitatively new level of application development systems and allows you to embed additional tools into this product that support almost all stages of application systems creation. Such a wide range of possibilities opens up thanks to the concept of so-called open interfaces implemented in Delphi, which is the link between the IDE (Integrated Development Environment) and external tools.

This article focuses on the Delphi open interfaces and provides an overview of the capabilities they represent. Delphi defines six open interfaces: Tool Interface, Design Interface, Expert Interface, File Interface, Edit Interface, and Version Control Interface. It is unlikely that within the framework of this article we would be able to illuminate in detail and illustrate the capabilities of each of them. The Delphi source codes will help you to understand the issues under consideration more thoroughly, since the developers have provided them with detailed comments. Class declarations representing public interfaces are contained in the corresponding modules in the ... \ Delphi \ Source \ ToolsAPI directory. The Design Interface (DsgnIntf.pas module) provides tools for creating property editors and component editors.

The editors of properties and components are a topic worthy of a separate discussion, so we just recall that the property editor controls the behavior of the Object Inspector when you try to change the value of the corresponding property, and the component editor is activated when you double-click the left mouse button on the image of the component placed on the form. Version Control Interface (VCSIntf.pas module) is intended for creating version control systems. Since version 2.0, Delphi supports the integrated version control system Intersolv PVCS, so in most cases there is no need to develop your own system. For this reason, we will also skip the Version Control Interface. File Interface (FileIntf.pas module) allows you to override the working file system of the IDE, which makes it possible to choose your own way of storing files (in Memo fields on the database server, for example). Edit Interface (the EditIntf.pas module) provides access to the source code buffer, which allows you to analyze and generate code, determine and change the cursor position in the code editor window, and control the syntax highlighting of the source text.

Special classes provide interfaces to the components placed on the form (defining the component type, getting references to parent and child components, accessing properties, passing focus, deleting, etc.), to the form itself, and to the project resource file. Edit Interface also allows you to identify the so-called modular notifiers that determine the reaction to events such as changing the source text of a module, modifying a form, renaming a component, saving, renaming or deleting a module, changing a project resource file, etc. Tool Interface (ToolIntf. pas) provides a means for developers to get general information about the state of the IDE and performing such actions as opening, saving and closing projects and individual files, creating a module, obtaining information about the current project (the number of modules and forms, their names, etc.), registration file system, organization of interfaces to individual modules, etc. In addition to modular notifiers, the Tool Interface defines add-in notifiers that notify of such events as opening / closing files and projects, loading and saving the desktop project file, adding / excluding project modules, installing / uninstalling packages, compiling a project. Unlike modular notifiers, add-in notifiers allow you to cancel the execution of some events.

In addition, the Tool Interface provides a means of accessing the main menu of the Delphi IDE, allowing you to build additional items into it. Expert Interface (module ExptIntf.pas) is the basis for creating Expert Advisors - software modules embedded in the IDE to extend its functionality. An example of an expert is the Delphi Database Form Wizard, which generates a form to view and change the contents of a database table. Once you've defined the expert class, you need to make sure Delphi “knows” about our expert. To do this, it must be registered by calling the RegisterLibraryExpert procedure, passing it an instance of the expert class as a parameter. As an illustration, let's create a simple esStandard-style Expert Advisor, which, when the corresponding Delphi menu item is selected, displays a message that it is running. As you can see from the above table, the esStandard style requires six methods to be overridden:

In order for the expert to be “put into action”, select the Component / Install Component ... menu item, select the module containing the expert (in our case, exmpl_01.pas) in the Browse dialog, click OK, and after compiling the dclusr30.dpk package in the main Delphi menu in the Help section, the item Simple Expert 1 should appear, when selected, the information message “Standard Expert started!” appears. Why Delphi puts the expert menu item in the Help section remains a mystery. If you do not like the fact that the menu item appears wherever Delphi, and not where you want, the following option is possible: create an expert in the add-in style, which excludes the automatic creation of the menu item, and add the menu item "manually" using the Tool Interface. This will allow you to set the location of the new item in the main menu in an arbitrary way.

To add a menu item, use the TIToolServices class - the basis of the Tool Interface - and the TIMainMenuIntf, TIMenuItemIntf classes that implement interfaces to the IDE's main menu and its items. The ToolServices instance of the TIToolServices class is created by the IDE itself when it is initialized. Note that the developer is solely responsible for releasing the interfaces to the Delphi main menu and items. Along the way, let's slightly complicate the functional load of the expert: when its menu item is activated, it will display information about the name of the project currently open in the environment: In this example, the AddIDEMenuItem function takes the central place, which adds a menu item to the main menu of the Delphi IDE. As parameters, the text of the new menu item, its identifier, the identifier of the item before which the new item is inserted, the symbolic representation of the key, which, together with the Ctrl key, can be used for quick access to the new item, and the event handler corresponding to the selection of a new item, are passed to it. We've added a new menu item to the View section before the Watches item.

Now let's get acquainted with notifiers. Let's define an add-in notifier that tracks the moments of closing / opening projects and accordingly adjusts the field storing the name of the active project (we will omit the implementation of methods that have not undergone changes in comparison with the previous example): To implement the notifier, we have defined the TAddInNotifier class, which is a descendant TIAddInNotifier, and overlapped the FileNotification. The IDE will call this method every time an event occurs that the add-in notifier is capable of responding to (each such event is denoted by a corresponding constant of type TFileNotification). The Expert field in the TAddInNotifier class is used for feedback with an expert (method TAddInNotifier.FileNotification). In the destructor of the expert, the registration of the notifier is removed and the notifier is destroyed. Let's now illustrate the use of modular notifiers. Let's create an add-in expert that issues messages about each act of saving the project file (we will not present the implementation of methods already familiar to us for brevity): In this example, the add-in expert monitors the events corresponding to the opening / closing of projects.

Each time a project is opened, a modular notification corresponding to the project file is registered. In terms of implementation, modular notifiers are similar to add-in notifiers: we define a TModuleNotifier class that is a descendant of TIModuleNotifier and override its Notify and ComponentRenamed methods. The IDE calls the Notify method when certain events related to this module are raised; within this method, the reaction to this or that event is determined. The ComponentRenamed method is called when the name of a component on a module form has changed. Please note that we do not use this method, but we must override it, otherwise when the name of the component changes, the abstract method of the base class will be called, which leads to unpredictable consequences.

Registering a modular notifier is a bit more complicated than registering an add-in notifier: first we get the module interface (TIModuleInterface), and then we register the notifier using the module interface. When the project is closed, the registration of the modular notifier is unregistered (again using TIModuleInterface) and the notifier is destroyed. Finally, we'll show you how you can determine the position of the cursor in the code editor window. Let us create an Expert Advisor that, upon selecting the corresponding menu item, would display a message containing the name of the active file and the position of the cursor in it (the implementation of only those essential for this example methods): To determine the position of the cursor, we must receive the following sequence of interfaces: modular interface (TIModuleInterface); code editor interface (TIEditorInterface); the interface of the module view in the editor window (TIEditView).

If the file with the source text (* .pas) is active when the expert menu item is selected, then a message is displayed containing the name of the active file and the current position of the cursor in it. If a non-pas-file is active, then the message is not displayed. The GetCurrentFile method of the TIToolServices class is used to get the name of the active file. This concludes the review of ways to use open interfaces. The CD-ROM contains the source code for all of the examples provided. The CD-ROM also contains a more complex and detailed example containing an add-in expert that allows the user to bookmark the source code of Delphi modules. A quick guide to installing and using the Bookmark Expert is contained in the bkmrks97.htm file. So, this article outlines open interfaces and provides examples of their use. Once again, we will repeat: thanks to the availability of the source code of the open interfaces, you can easily figure out the details that interest you. We hope that the variety of possibilities provided by open interfaces will give you more than one bold and useful idea.


2021
maccase.ru - Android. Brands. Iron. news