Skip to main content

How to Add an Editor from the Editor Repository

  • 2 minutes to read

This topic describes how you can quickly create an editor and insert it into a bar using the editor repository.

The editor repository is represented by the TcxEditRepository component. It stores a collection of pre-configured editors and allows developers to quickly create the required editor and insert it into a bar.

To use editors from the editor repository in your application, do the following:

  1. Drop the TcxEditRepository component from the Component Palette (this component is located on the Express Utilities page) onto a form.

  2. Double-click the dropped icon or select Edit from its context menu to open the repository dialog.

  3. In the repository dialog, click the Add button to show the Select EditRepositoryItem dialog. Choose the repository item that relates to the editor you need (in this example, the SpinEdit item).

  1. Using the Object Inspector, name it SpinItem.

  1. Assign this repository item to the TcxBarEditItem.RepositoryItem property in order to place the editor into a bar (in this example into the Custom 1 bar) as shown in the code below.

The sample code below assumes that this bar has already been added to the ExpressBars6MainForm form.

uses
  ..., cxSpinEdit, cxBarEditItem, cxEditRepositoryItems;
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
          RepositoryItem := SpinItem;
          Caption := 'Spin Edit';
          ShowCaption := True;
        end;
      finally
        EndUpdate;
      end;
    end;
  end;
end;

Note

To use an editor from the editor repository in code, pass TcxBarEditItem as an argument into the TdxBarItemLinks.AddItem method. The example above assumes that the bar named Custom 1 has already been added to the ExpressBars6MainForm form.

The image below shows the embedded spin editor when the application runs.

See Also