Back to Devexpress

How to Add a Standalone Editor to a Toolbar

vcl-155067-expressbars-how-to-add-a-standalone-editor-to-a-toolbar.md

latest3.5 KB
Original Source

How to Add a Standalone Editor to a Toolbar

  • Dec 28, 2020
  • 2 minutes to read

In addition to built-in bar editors, the ExpressBars Suite also allows you to place standalone editors from the ExpressEditors library onto any toolbar or menu. This topic demonstrates how to add a standalone editor from this library to a toolbar at design and runtime.

To add an editor programmatically you need to:

The following code snippet adds a TcxCalcEdit, and it assumes that a bar named Custom 1 has already been added to the ExpressBars6MainForm form.

delphi
uses
  ..., cxCalc, cxBarEditItem;
procedure TExpressBars6MainForm.FormCreate(Sender: TObject);
var
  ABarManager : TdxBarManager;
  ABar : TdxBar;
  ABarEditItem: TcxBarEditItem;
begin
  ABarManager := GetBarManagerByForm(ExpressBars6MainForm);
  with ABarManager do
  begin
    ABar := BarByCaption('Custom 1');
    if ABar <> nil then
    begin
      BeginUpdate;
      try
        ABarEditItem := TcxBarEditItem(ABar.ItemLinks.AddItem(TcxBarEditItem).Item);
        with ABarEditItem do
        begin
          PropertiesClass := TcxCalcEditProperties;
          Caption := 'Calc Edit';
          ShowCaption := True;
        end;
      finally
        EndUpdate;
      end;
    end;
  end;
end;
cpp
#pragma link "cxCalc"
#pragma link "cxBarEditItem"
// ...
void __fastcall TExpressBars6MainForm::FormCreate(TObject *Sender)
{
  TdxBarManager * ABarManager;
  TdxBar * ABar;
  TcxBarEditItem * ABarEditItem;
  ABarManager = GetBarManagerByForm(ExpressBars6MainForm);
  ABar = ABarManager->BarByCaption("Custom 1");
  if (ABar != NULL)
  {
    ABarManager->BeginUpdate();
    try
    {
      ABarEditItem = (TcxBarEditItem*)(ABar->ItemLinks->AddItem(__classid(TcxBarEditItem))->Item);
      ABarEditItem->PropertiesClass = __classid(TcxCalcEditProperties);
      ABarEditItem->Caption = "Calc Edit";
      ABarEditItem->ShowCaption = True;
    }
    __finally
    {
      ABarManager->EndUpdate();
    }
  }
}

The following image shows the result when the above code executes.

To add a standalone editor at design time, right-click the desired bar and choose Add cxEditItem and then select the appropriate editor type within the submenu (see the image below).

See Also

TcxCustomBarEditItem.PropertiesClass

TcxCustomBarEditItem.PropertiesClassName

TdxBarItem.Caption

TdxBarItemLinks.AddItem

TdxCustomBarEdit.ShowCaption

How to Add an Editor from the Editor Repository