unit MainUnit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, uDMDB;

type
  TMainForm = class(TForm)
    TreeView1: TTreeView;
    bInsert: TButton;
    bDelete: TButton;
    bUpdate: TButton;
    bEdit: TButton;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure bInsertClick(Sender: TObject);
    procedure bEditClick(Sender: TObject);
    procedure bUpdateClick(Sender: TObject);
    procedure bDeleteClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);


  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  DMDB:TDMDB;


implementation

{$R *.dfm}

procedure TMainForm.bDeleteClick(Sender: TObject);
begin
DMDB.DeleteNode(Self,TreeView1);
end;

procedure TMainForm.bEditClick(Sender: TObject);
begin
DMDB.EditNode(Self,TreeView1);
end;

procedure TMainForm.bInsertClick(Sender: TObject);
begin
DMDB.InsertNodeInTree(Self,TreeView1);
end;

procedure TMainForm.bUpdateClick(Sender: TObject);
var i:integer;
begin

DMDB.UpdateTree(Self,TreeView1);

for i := 0 to TreeView1.Items.Item[i] do
  begin

  end;

end;



procedure TMainForm.Button1Click(Sender: TObject);
begin
// if TreeView1.Selected<>nil then
// showmessage(TreeView1.Selected.Text);

 TreeView1.SetFocus;
 TreeView1.Items.Item[1].Selected:=true; // << Установка фокуса на элементе

end;


procedure TMainForm.FormShow(Sender: TObject);
begin

DMDB:=TDMDB.Create(Self);

DMDB.Connect(Self);
if DMDB.FDConnection.Connected then Self.Caption:=Self.Caption+' Connected to DB';

Self.bUpdate.Click;

end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 DMDB.ClearTree(TreeView1);
end;

end.
