the Internet Windows Android

1C How to create a table of values. What methods exist and how to search simultaneously in several values

Greetings all readers Infostart'a. This article will be devoted to the creation of an arbitrary table of values \u200b\u200bon the form of a managed application programmatic method.

Features of the task.

Everyone who programmed in by the usual applicationoften faced with the task of obtaining an arbitrary table of values \u200b\u200bon the form. Under an arbitrary table of values \u200b\u200bis understood as the table, the number and type of columns of which is not known. That is, the columns can be 3, and maybe 6, or maybe 8. In the usual application, everything is simple: it was possible to place the "table apposition" element on the formation form, and then transfer the value table to the values \u200b\u200bto this item to this item. Then a simple team:

Elementforms. Ticketpassed. Calcons ();

get a ready-made table of values \u200b\u200bon the form. It would seem that it could be easier.

It was all in the usual application. In the managed application everything has changed. So simply an arbitrary table not to create. Now you need to either rigidly parametrate the table of values \u200b\u200bon the form, or create it programmatically (describe, well, in this, in fact, the essence of the authorized application itself). This we will try to do: software Create an arbitrary table of values \u200b\u200bon a managed form.

The solution of the problem.

The first thing we have to do is determine how the table appears on the form. The main thing is that no element of the form in the processing is not necessary. We will create it programmatically, like the entire table. That is, the table will be described, and to create at the time of opening the form or using the button - this is how it is necessary.

Creating a table on the form occurs through the description of the table of values \u200b\u200bas requisition:
Massiferboabor \u003d new array; Massifable customer. Addly (type ("table apposition")); DescriptionCarebar \u003d New descriptions (massifacivity); Massives \u003d New array; Massives. Addly (new requisite ("tablescript", descriptions, "", "TZN")); Now we have to create a software table of values \u200b\u200bthat contain data. If the value table is obtained from the request, then everything is less than the order. If the table is created manually, the value of the speakers that will contain numbers or dates can be created through the "Description". The bottom line is that the columns in the table of values \u200b\u200bmust have some kind of type. If, for example, it is assumed that the user will fill in the data in these columns interactively, then you cannot add the values \u200b\u200bof the values \u200b\u200bcolumn simply with the name, it should be type. Keep in mind - this is very important because We will give these types to the table on the form.
Create a table that contains several columns:
KD \u003d new qualificatory dates (particles. Veria); Massigs \u003d new array; Arms. Addly (type ("date")); Lookup graphics \u003d New descriptions (arms, CD); TK \u003d new tables;
TK.Colonki. Addly ("C", descriptions.
TK.Colonks. Addly ("to", descriptions.
TK.Colonki. Addly ("FULL NAME");
TK. Solonks. Addly ("Note"); // FULL NOTE - Rows Next, we will fill our software table TK with the necessary data. We obtain the TK table that contains the necessary values \u200b\u200band is ready for transmission to the created props of form. For each column of TK. Column cycle

Massiverevizites. Addly (new requisite (column. I mean, column. Type, "Taxcripts"));
EndCycle;
Changerevizes (massivevizites);
TablePoles Captivity \u003d Elements. Addly ("TZN", type ("tableform"));
TablePoles Capture. Powded \u003d "Taxcripts";
TablePoleSeboat. Example \u003d Displayed. Opportisses;

Here is such a simple combination and our table is ready.

For each column of TK. Column cycle

NewElent \u003d Elements. Addly (column. I mean, type ("Foreform"), TablePoles);
New element. Vid \u003d Vidpolar Form. Power;
New element. Powdly \u003d "Taxcripts." + Column.
New element.shirina \u003d 10;
EndCycle;

Conditional design, if we need we also write manually, command menu - manually. Table handlers are also written with hands. For example, to add an event handler "Selection" event:

TablePoles Capture. Setting ("Choice", "Tznvybor");

To process this event, a separate procedure is prescribed in the form of the procedure:

& Svalette
Procedure TZNVSB (TK, selected, field, standardworking)
// Processor Commands End Controlments

Please note that the table handlers are triggered on the client and therefore must have a compiler pointer command

& Svalette

Well, and the last thing I wanted to add that after all these actions, we definitely do not forget to transfer the finished table into the requisition of the form:

Recentlyrerevisitforms (TK, "Taxcripts");

Here is what we have as a result:


But the processing of the Event "Choice":



Afterword.

I hope the article will assist those programmers 1C, which begin to create tables on the form of the programmatic method.

You can download the processing that software creates a value table and displays the managed form With comments that will help you create your tables.

Search in 1c values \u200b\u200btable

What methods exist and how to search simultaneously in several values.

To search in the table of values \u200b\u200bthere are two special methods:

1. Find

TVGorizont \u003d reference books. Nomelaclature. Intepponation ("TV horizon");
Results \u003d Tznenenclature. Inite (TV, TV);
// Also we can specify in which speakers to search to speed up the search
Foundation \u003d Tznomenclature. Inite (TV, "Nomenclature");

This method returns the first found line with the desired value or undefined if it does not find. So it is convenient to use to search unique valuesbecause Otherwise, you will have to delete it from the table when finding the following.

So that it does not suffer next methodwhich allows you to find an array of suitable lines:

2. Flight


Structuralboration. Hold ("Nomenclature", TVGorizont); // First, specify the column where to look for, and then what to look for.

This method always returns an array, but it can be empty if nothing is found. And this method also, as well as the previous returns the rows of the values \u200b\u200bof the values, and not the values \u200b\u200bthemselves in a separate array. Therefore, changing the values \u200b\u200bin the array row or in the previous method at the found line, you will change the value in the table of values \u200b\u200bprocessed.

The more good this method is that it can search at once in several columns of the values \u200b\u200btable at the same time:


Structures \u003d new structure;
Structuralboration. Hold ("Nomenclature", TVGorizont);
Structuralboat. Hold ("quantity", 10);
FoundationMassivests \u003d Tznenenclature. Entries (structures);

The only minus, as can be seen, can not be used other comparisons except "equal"

Table of values \u200b\u200bis a specific universal objectDesigned to store data in a tabular view. The key difference of the table from applied objects is the lack of binding to the physical database tables. Table of values \u200b\u200bexists only in random access memoryIn one hand, it gives unique opportunities, and on the other, it imposes certain limitations. Nevertheless, the possibility of interaction with the table is comparable to the interaction with the objects actually existing in the database.

Historically, the value table in 1C has a dual purpose, being a virtual analogue of existing tables, but at the same time - and controls element. With the transition to the controlled application, most of this functionality is outdated, but also at present it can also be an element of the user interface, but with a number of significant restrictions.

Structure of the table of values \u200b\u200bas an object

The properties of the values \u200b\u200btable are determined by combinations of two predefined collections: its columns and rows.

Table of speaker values

Column Table of values \u200b\u200b- its defining property. It is a set of table columns determines its structure. The columns match the fields of physical tables or familiar to the user interface columns tabular part or documents log. The column may have an internal name, the value of the value and the title displayed during interactive working with the table.

Since the columns are a collection of objects, you can add, delete and edit columns.

Row of table of values

From the point of view of the software interface, the string is a separate collection built into the values \u200b\u200btable. They are analogous to the records of physical tables, that is, the usual lines of the table part or the log log. Each separately taken line is an object with a set of named properties whose names correspond to the names of the table columns.

Thus, interaction with the string is very similar to the interaction with other objects. You can read and write its properties, including using the predefined function of "filling out the following ()". Since the lines are the main collection of the values \u200b\u200btable, then to delete all rows of the table, the "Clear ()" method applies.

Create a table of values

There are many ways to get the table of values \u200b\u200bready for use. Consider some of them. Each example will be given as the listings of the code with comments.

Creating a table designer

The main way to create just such a table that is needed by the developer, unfortunately, the most time consuming, since it requires manually by manually all the necessary properties of the table.

Demotable \u003d new tables; // First of all initialize TK // Next, we define the necessary parameters for new columns and add them to the collection // Creating a "Nomenclature" column name \u003d "Nomenclature"; Type Type \u003d New Description ("DirectoryAds.Nanklatura"); Title \u003d "Nomenclature (product)"; Demotablik. Cutouts. Addly (to them, title, title); // Creating a column "Number" Name \u003d "Number"; Type title \u003d new descriptions ("number"); Demotable. Cutouts. Addly (name, title); // As a result of data of manipulations, we have created an empty table with typed columns // If you need to use more accurate typing primitive typesYou should use the advanced syntax of the Designer Designer "Desigratypov"

Creating a copy table

If your hand has a standard with a suitable structure and / or composition, you can copy or unload the reference table of values. If the reference is another table, you must apply the "Copy Stand Table" method. If you deal with tabular part or a set of register entries, you need to use the "Unload Table" method. If you need only a structure, you can use the "Copying Collection" method.

// Option with copying from the TK standard of all rows, but with the preservation of only the two specified columns of the columnalone \u003d "Nomenclature, number"; Demotable \u003d TableThetalon .Copy (, columnal); // Option with copying from the TK standard of pre-selected rows, while maintaining the two specified columns of the stringalone \u003d selected by the machine-to-thenemstroyistalkyetalone (); Columnalone \u003d "nomenclature, number"; Demotable \u003d TableThetalon .Copy (rowetal, columnal); // Option with copying from TK-Strelna Rows by the specified filter, while saving one column "Nomenclature" // All lines will be selected where the value in the column is equal to 0, only the column of the nomenclature of the remedies will fall into the resulting table ("Quantity" 0); Columnaltalon \u003d "nomenclature"; Demotable \u003d TableThetalon .Copy (rowetal, columnal); // Option with full copying of the table and the subsequent removal of one row with the field value of the quantity of zero is zero and the removal of the whole column "Number" of the counterpart \u003d New Structure ("Number", 0); Columnaltalon \u003d "nomenclature"; Demotable \u003d TableThetalon .Copy (rowetal, columnal); Strifices \u003d Demotable .Night (0, "quantity"); Demotable. Delete (strifices); Demotablik. Solonki.Deel ("quantity"); // Similar options and their modifications can be applied to tabular parts and sets of registers

Creating a table inquiry

If there is a reference table in the database in the database, you can use the request for fast creation Tables with the desired structure.

// Example with the creation of an empty table according to the sample structure of the accumulation register // It is not difficult to guess that in this way you can get the filled table request \u003d a new query ("Select the first 0 * from the register. RESULT SUPPLY \u003d Query. Fill (); Demotable \u003d result recruitment. Download (); // Example with the creation of an empty table by explicitly specified types and names of the fields query \u003d a new request; Request.text \u003d "Select the first 0 | meaning (reference book. Substitution. Power roll) as a nomenclature, | express (0 as a number (15, 3)) as a quantity"; RESULT SUPPLY \u003d Query. Fill (); Demotable \u003d result recruitment. Download (); // IMPORTANT! You should not forget that in the types of speaker values \u200b\u200bobtained from the query is always present type NULL // Thus, the TK created by the query always has composite types of columns

Conclusion

In this small article, we reviewed the basic properties and practical techniques for creating a table of values \u200b\u200bsufficient to understand and start application. The object of the table of the values \u200b\u200bis so multifaceted that detailed description Its capabilities requires writing a separate article on the receptions and methods of work.