unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, NxPropertyItems, NxPropertyItemClasses, StdCtrls,
  ExtCtrls, ImgList, ComCtrls, NxScrollControl,
  NxInspector;

type
  TForm1 = class(TForm)
    NextInspector1: TNextInspector;
    NextInspector2: TNextInspector;
    Label1: TLabel;
    Label2: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    ImageList1: TImageList;
    NxTextItem1: TNxTextItem;
    NxTextItem2: TNxTextItem;
    NxSpinItem1: TNxSpinItem;
    NxTrackBarItem1: TNxTrackBarItem;
    NxComboBoxItem1: TNxComboBoxItem;
    NxDateItem1: TNxDateItem;
    NxButtonItem1: TNxButtonItem;
    NxColorItem1: TNxColorItem;
    NxImagePathItem1: TNxImagePathItem;
    NxFontNameItem1: TNxFontNameItem;
    NxTextItem3: TNxTextItem;
    NxRadioItem1: TNxRadioItem;
    NxRadioItem2: TNxRadioItem;
    NxRadioItem3: TNxRadioItem;
    NxTextItem4: TNxTextItem;
    NxToolbarItem1: TNxToolbarItem;
    NxAlignmentItem1: TNxAlignmentItem;
    NxFontStyleItem1: TNxFontStyleItem;
    NxVertAlignmentItem1: TNxVertAlignmentItem;
    NxCheckBoxItem1: TNxCheckBoxItem;
    NxTextItem5: TNxTextItem;
    NxTextItem6: TNxTextItem;
    NxAlignmentItem2: TNxAlignmentItem;
    NxFontNameItem2: TNxFontNameItem;
    NxColorItem2: TNxColorItem;
    NxTextItem7: TNxTextItem;
    NxCheckBoxItem2: TNxCheckBoxItem;
    NxToolbarItem2: TNxToolbarItem;
    NxToolbarItem3: TNxToolbarItem;
    procedure NextInspector1SelectItem(Sender: TObject;
      Item: TNxPropertyItem);
    procedure FormCreate(Sender: TObject);
    procedure NextInspector1ToolbarClick(Sender: TObject;
      Item: TNxPropertyItem; ButtonIndex: Integer);
    procedure NextInspector1Execute(Sender: TObject;
      Item: TNxPropertyItem);
    procedure NextInspector1Edit(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString; var Accept: Boolean);
    procedure NextInspector2Change(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString);
    procedure NextInspector2Edit(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString; var Accept: Boolean);
    procedure NextInspector1Change(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString);
    procedure NextInspector1SuffixEdit(Sender: TObject;
      Item: TNxPropertyItem; Value: WideString);
    procedure NxButtonItem1ButtonClick(Sender: TNxPropertyItem);
  private
    { Private declarations }
  public
    procedure UpdateProperties;
  end;

var
  Form1: TForm1;
  PropertiesUpdating: Boolean = False; { Used to avoid recursive update }

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.NextInspector1SelectItem(Sender: TObject;
  Item: TNxPropertyItem);
begin
  UpdateProperties; { update right properties view }
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Category1, Category2: TNxPropertyItem;
begin
  { added in run-time }
  PropertiesUpdating := True;
  with NextInspector2 do
  begin
    Category1 := Items.AddChild(nil, TNxTextItem, 'SelectedItem');
    Items.AddChild(Category1, TNxTextItem, 'AsString');
    Items.AddChild(Category1, TNxCheckBoxItem, 'Enabled').AsBoolean := True;
    Items.AddChild(Category1, TNxCheckBoxItem, 'Visible').AsBoolean := True;
    Items.AddChild(Category1, TNxCheckBoxItem, 'ShowText');

    Category2 := Items.AddChild(nil, TNxTextItem, 'Settings');
    with Items.AddChild(Category2, TNxSpinItem, 'RowHeight') do
    begin
      AsInteger := NextInspector1.RowHeight;
      Options := Options + [itoAutoApply];
    end;
  end;
  PropertiesUpdating := False;
end;

procedure TForm1.UpdateProperties;
var
  AItem: TNxPropertyItem;
begin
  AItem := NextInspector1.SelectedItem;
  PropertiesUpdating := True;
  with NextInspector2 do
  begin
    Items[0].Item[0].AsString := AItem.Value;
    Items[0].Item[1].AsBoolean := AItem.Enabled;
    Items[0].Item[2].AsBoolean := AItem.Visible;
    Items[0].Item[3].Enabled := AItem is TNxToolbarItem;
    if AItem is TNxToolbarItem then
    begin
      Items[0].Item[3].AsBoolean := TNxToolbarItem(AItem).ShowText;
    end;
  end;
  PropertiesUpdating := False;
end;

procedure TForm1.NextInspector1ToolbarClick(Sender: TObject;
  Item: TNxPropertyItem; ButtonIndex: Integer);
begin
  UpdateProperties;
  if Item.ClassType = TNxVertAlignmentItem then ShowMessage(TNxToolbarItem(Item).Buttons[ButtonIndex].Text);
end;

procedure TForm1.NextInspector1Execute(Sender: TObject;
  Item: TNxPropertyItem);
begin
  if Item.Caption = 'TNxButtonItem' then
    if Form2.ShowModal = mrOk then Item.Value := Form2.Edit1.Text;
end;

procedure TForm1.NextInspector1Edit(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString; var Accept: Boolean);
begin
  UpdateProperties;
end;

procedure TForm1.NextInspector2Change(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString);
begin
  if PropertiesUpdating then Exit;
  if Item.Caption = 'ShowText' then
    with Item as TNxToolbarItem do
      TNxToolbarItem(NextInspector1.SelectedItem).ShowText := AsBoolean;

  if Item.Caption = 'Enabled' then
    with Item as TNxToolbarItem do
      NextInspector1.SelectedItem.Enabled := AsBoolean;

  if Item.Caption = 'Visible' then
    with Item as TNxToolbarItem do
      NextInspector1.SelectedItem.Visible := AsBoolean;

  if Item.Caption = 'PreviewBox' then
    with Item as TNxCheckBoxItem do TNxTextItem(NextInspector1.SelectedItem).ShowPreview := AsBoolean;

  if Item.Caption = 'Style' then
    with Item as TNxFontStyleItem do NextInspector1.SelectedItem.Font.Style := StringToFontStyles(AsString);

  if Item.Caption = 'FontName' then NextInspector1.SelectedItem.Font.Name := Value;
  if Item.Caption = 'Color' then NextInspector1.SelectedItem.Font.Color := StringToColor(Value);
  if Item.Caption = 'Size' then NextInspector1.SelectedItem.Font.Size := StrToInt(Value);
  if Item.Caption = 'RowHeight' then NextInspector1.RowHeight := Item.AsInteger;
  if Item.Caption = 'Use Themes' then NextInspector1.EnableVisualStyles := Item.AsBoolean;
end;

procedure TForm1.NextInspector2Edit(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString; var Accept: Boolean);
begin
  if Item.Caption = 'AsString' then NextInspector1.SelectedItem.AsString := Value;
end;

procedure TForm1.NextInspector1Change(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString);
begin
  UpdateProperties; { update right properties view }
end;

procedure TForm1.NextInspector1SuffixEdit(Sender: TObject;
  Item: TNxPropertyItem; Value: WideString);
begin
  UpdateProperties; { update right properties view }
end;

procedure TForm1.NxButtonItem1ButtonClick(Sender: TNxPropertyItem);
begin
  ShowMessage('Click on Button');
end;

end.
