unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
TreeView1: TTreeView;
BackButton: TButton;
ForwardButton: TButton;
procedure TreeView1Changing(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
procedure FormCreate(Sender: TObject);
procedure BackButtonClick(Sender: TObject);
procedure ForwardButtonClick(Sender: TObject);
private
HistoryArray:array of integer;
HistoryCursor,HistoryMax:integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.TreeView1Changing(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
begin
if (HistoryArray[HistoryCursor])=Node.AbsoluteIndex then Exit;
HistoryArray[HistoryCursor]:=TreeView1.Selected.AbsoluteIndex;
Inc(HistoryCursor);
HistoryArray[HistoryCursor]:=Node.AbsoluteIndex;
HistoryMax:=HistoryCursor;
ForwardButton.Enabled:=false;
BackButton.Enabled:=true;
if HistoryCursor>High(HistoryArray) then SetLength(HistoryArray,Length(HistoryArray)+10);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetLength(HistoryArray,10);
HistoryCursor:=0;
HistoryMax:=0;
end;
procedure TForm1.BackButtonClick(Sender: TObject);
begin
Dec(HistoryCursor);
TreeView1.Selected:=TreeView1.Items[HistoryArray[HistoryCursor]];
ForwardButton.Enabled:=true;
if (HistoryCursor=0) then BackButton.Enabled:=false;
end;
procedure TForm1.ForwardButtonClick(Sender: TObject);
begin
Inc(HistoryCursor);
TreeView1.Selected:=TreeView1.Items[HistoryArray[HistoryCursor]];
BackButton.Enabled:=true;
if HistoryCursor=HistoryMax then ForwardButton.Enabled:=false;
end;
end.