📜 ⬆️ ⬇️

The basic principle of programming a controlled form in 1C

The purpose of the article is to show the application of the Remote Facade and Data Transfer Object templates to the structuring of code, a managed form in the 1C 8.2 environment.


Introduction


Let's start with a brief description of the concept of “controlled form” and related concepts of the 1C platform. Platform experts can skip this section.

In 2008, a new version of the 1C: Enterprise 8.2 platform (hereinafter Managed Application) became available, which completely changes the entire layer of work with the interface. This includes the command interface, the forms, and the window system. At the same time, not only the user interface development model in the configuration is changing, but also a new architecture for the separation of functionality between the client application and the server is proposed.
The managed application supports the following types of clients:

The managed application uses forms built on the new technology. They are called Managed Forms . To facilitate the transition, the old forms (so-called Normal forms) are also supported, but their functionality is not developed and they are available only in the launch mode of the thick client.
The main differences of the managed forms for the developer:

We list the compilation directives of the form methods:

We illustrate the above. The screenshot shows an example of a managed form and its module in development mode. Find the declarative description, details, compilation directives, etc.

')
All further considerations will be about the right part of the illustration, about how to structure the module code and what principles will allow to implement effective client-server interaction.

Denote the problem


Several years have passed since the new version of the 1C platform has been actively used and a lot of solutions (configurations) have been released both by 1C and its numerous partners.
During this time, did the developers have a common understanding of the principles of client-server interaction when creating forms, and has the approach to the implementation of software modules changed in the new architectural realities?

Consider the structure of the code (form module) in several forms of the same typical configuration and try to find patterns.
By structure, we mean sections of code (most often these are blocks of comments) allocated by the developer for grouping methods and compilation directives for these methods.
Example 1:
    –   –   -           

Example 2:
          

Example 3:
                     

Example 4:
         « » 

In essence, the structure of the code is missing, or, to put it mildly, it is similar to what was in Forms 8.1:

Why is the code structure needed?


Why the existing development standard from 1C does not help?

Let's look at the principles recommended for writing a managed form published on ITS disks and in various “Developer’s Manuals ...”.

These are slogans that are absolutely correct, but how to implement them? How to minimize the number of calls, what does programming in client-server mode mean?

Design patterns or the wisdom of generations


Client-server interaction has been used in various software technologies for decades. The answer to the questions indicated in the previous section has long been known and summarized in two basic principles.

A word to Martin Fowler , his description of these principles:


Examples of patterns in the platform 1C

The application programming interface available to the developer in developing the managed form contains many examples of these principles.
For example, the OpenForm () method, a typical “hardened” interface.
  =  ("1, 2, 3", 1, 2, 3);  = (, ); 

Compare with the v8.1 style.
  = (); .1 = 1; .2 = 2; .(); 


In the context of the managed form, the set of “Data Migration Objects”. You can select the system and the developer defined .
The system models on the client an application object, in the form of one or more form data elements. You cannot create them outside the binding to the form details.

Conversion of system data transfer objects to application types and back is performed by the methods:

Often an explicit transformation is used when adapting an existing solution. Methods can expect (use features) input parameters, such as Table Values, not Data Forms, or the method has been defined in the context of the application object and has become unavailable for a direct call from the form.
Example 1C v8.1:
 //      () 

Example 1C v8.2:
 //       = (""); .(); (, ""); 


Data transfer objects whose structure is determined by the developer is a small subset of the types available on both the client and the server. Most often, the following parameters are used as parameters and results of the “hardened” interface methods:

Example: the method takes a list of orders for changing status and returns a description of errors to the client.
 &  (, )  =  (); // [][ ]       ();   = .(); ….  ,     …  (); .(, ()); ; ;  ;  // () 


Structure the code


The main goals that the managed form module should reflect and the approaches to the solution.

Below is the basic structure of the module that implements these goals.




 //////////////////////////////////////////////////////////////////////////////// // <(c) ="<?"", >" ="<?"", ,"=dd.MM.yyyy">"/> // <> // <?> // </> //////////////////////////////////////////////////////////////////////////////// //   //////////////////////////////////////////////////////////////////////////////// //   //*******    ******* &  (, ) //    //*******    ******* //******* -   ******* //////////////////////////////////////////////////////////////////////////////// //      //////////////////////////////////////////////////////////////////////////////// //   //******* -   ******* //*******  ******* //*******    ******* //////////////////////////////////////////////////////////////////////////////// //    


Related Issues

In conclusion, we denote several directions that it is useful to think about when programming client-server interaction.

Source: https://habr.com/ru/post/134151/


All Articles