Modules and events
Module kinds, write events, fill checks, common modules and event subscriptions.
8 questions
JuniorTheoryVery commonWhich kinds of modules does a 1C configuration have?
Which kinds of modules does a 1C configuration have?
Application-wide: the managed application module, the session module and the external connection module. Per object: the object module, the manager module and the record set module. Plus form, command and common modules.
Common mistakes
- ✗Putting object events into a common module:
ПередЗаписьюandОбработкаПроведенияbelong in the object module - ✗Writing type-wide code in the object module: code that needs no instance belongs in the manager module
Follow-up questions
- →Which module's events run when a user starts the thin client?
- →Where does the code of a command added to a document's form live?
JuniorTheoryVery commonHow does an object module differ from a manager module?
How does an object module differ from a manager module?
The object module holds code for one instance, the item or document being written: its events such as ПередЗаписью and methods using ЭтотОбъект. The manager module holds code for the type as a whole, called as Справочники.Товары.ИмяМетода().
Common mistakes
- ✗Calling an object module method through the manager: it needs an instance, created or got from a reference
- ✗Putting a function that searches the catalog into the object module: it needs no instance and belongs in the manager module
Follow-up questions
- →Which event of the manager module lets you choose the form that opens?
- →How do you call an object module's export method for a document you have only a reference to?
MiddleTheoryVery commonWhich flags does a common module have, and what do they control?
Which flags does a common module have, and what do they control?
«Клиент», «Сервер» and «Внешнее соединение» set where the code is compiled; «Вызов сервера» lets the client call it; «Глобальный» drops the module name from calls; «Привилегированный» skips rights checks. Reuse of return values caches results.
Common mistakes
- ✗Marking a module «Глобальный» without need: it is compiled at start and slows the launch
- ✗Setting «Привилегированный» to get around rights: the module then skips every rights check, which is a security risk
Follow-up questions
- →When can reuse of return values for the whole session give stale results?
- →How would you split code between a client module and a server-call module?
JuniorTheoryCommonWhy does a common module need the «Вызов сервера» flag?
Why does a common module need the «Вызов сервера» flag?
So that its export methods are called from the client and run on the server
Common mistakes
- ✗Confusing «Вызов сервера» with «Привилегированный»: the first lets the client call the methods, the second skips the rights check
- ✗Expecting the client to call any method of such a module: only the export methods are open to it
Follow-up questions
- →How does a common module with «Сервер» but without «Вызов сервера» look to the client?
- →Which name suffix do the 1C standards give a module with the «Вызов сервера» flag?
JuniorTheoryCommonWhat are the session module and the application module for?
What are the session module and the application module for?
The session module runs on the server when a session starts, mainly to fill session parameters in УстановкаПараметровСеанса. The managed application module runs on the client and handles start and exit events such as ПриНачалеРаботыСистемы.
Common mistakes
- ✗Filling session parameters in the application module: it runs on the client, while session parameters are set on the server in the session module
- ✗Putting heavy work into
ПриНачалеРаботыСистемы: every user waits for it at start
Follow-up questions
- →What happens when code reads a session parameter that has not been set yet?
- →Which application module event lets you stop the user from closing the program?
JuniorTheoryCommonIn what order do the messages appear when a new document is written with posting?
In what order do the messages appear when a new document is written with posting?
ПередЗаписью, ПриЗаписи, ОбработкаПроведения
Open full question →Common mistakes
- ✗Expecting
ОбработкаПроведенияbeforeПриЗаписи: the document is written first, and only then does the platform make its movements - ✗Expecting
ПриЗаписиto fire when the write starts:ПередЗаписьюcomes first, andПриЗаписиfollows the write
Follow-up questions
- →Where does
ОбработкаПроверкиЗаполненияfit into this chain when the document is written from a form? - →What happens to the write if
ПриЗаписиsetsОтказ = Истина?
MiddleTheoryCommonHow does ОбработкаПроверкиЗаполнения differ from a check in ПередЗаписью?
How does ОбработкаПроверкиЗаполнения differ from a check in ПередЗаписью?
ОбработкаПроверкиЗаполнения runs on a write or posting from a form, before ПередЗаписью and outside the transaction; a write from code skips it unless the code calls ПроверитьЗаполнение(). ПередЗаписью runs on every write, inside it.
Common mistakes
- ✗Relying on
ОбработкаПроверкиЗаполненияfor data written from code: a write from code skips it - ✗Expecting the fill check to run inside the write transaction: it runs before the transaction and outside it
Follow-up questions
- →How do you run the fill check before writing an object from code?
- →Which attribute property makes the platform itself check that an attribute is filled?
MiddleTheoryCommonHow does an event subscription differ from a handler in the object module?
How does an event subscription differ from a handler in the object module?
A subscription attaches one handler from a common module to an event of many object types at once, such as ПередЗаписью of every document, without editing their modules. A handler in the object module serves only its own object type.
Common mistakes
- ✗Copying the same handler into many object modules: one subscription covers all those types
- ✗Forgetting that a subscription handler gets the object as its first parameter,
Источник, rather thanЭтотОбъект
Follow-up questions
- →Which parameters does a subscription handler for
ПередЗаписьюreceive? - →Why can a careless subscription slow down every write in the configuration?