Add(Type: PrxToolbarAddElementType): IPrxToolbarElement;
Type. Type of added toolbar element.
The Add method adds an element of the specified type to the toolbar.
This method is used to add separators or custom groups of buttons.
Custom buttons are created in the IPrxUserButtons collection. After this, custom buttons can be moved to the required position in the IPrxToolbarElements collection.
To execute the example the repository must contain a regular report with the REPORT identifier. The toolbar can be changed in a report. The file system should contain the button image file D:\Work\Image\btn16x16.png.
Add links to the IO, Metabase, and Report system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
Report: IPrxReport;
Toolbar: IPrxToolbar;
Elements: IPrxToolbarElements;
Group: IPrxToolbarElement;
UserBtn: IPrxUserButton;
Begin
Mb := MetabaseClass.Active;
// Get regular report
Report := Mb.ItemById("REPORT").Edit As IPrxReport;
// Get toolbar
Toolbar := Report.Toolbar;
// Create a separator and custom groups of buttons
Elements := Toolbar.Elements;
Elements.Add(PrxToolbarAddElementType.Separator);
Group := Elements.Add(PrxToolbarAddElementType.UserGroup);
Group.Name := "Manage calculation";
// Create a custom button
UserBtn := Report.UserButtons.AddByType(PrxUserButtonType.Method);
UserBtn.Name := "Start calculation";
UserBtn.ForeModule := Mb.ItemById("MOD_ACTION");
UserBtn.Icon := New FileStream.Create("D:\Work\Image\btn16x16.png", FileOpenMode.Read, FileShare.DenyNone);
UserBtn.IconType := "png";
UserBtn.SmallIcon := False;
(UserBtn.Action As IPrxUserButtonActionForeMethod).ForeMethod := "Run";
// Move button to custom group
// because button is added at the end of the toolbar, button index can be obtained using the number of elements
Elements.MoveTo(Elements.Count - 1, 0, (Group As IPrxUserGroupElement).Elements);
// Save changes
Report.MetabaseObject.Save;
End Sub UserProc;
After executing the example the following is added to the toolbar of the specified report: separator, custom group of buttons, and custom button that executes Fore method. The button will be moved to the created group. The required settings will be determined for new elements.
See also: