unit FRM_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ActnList;
type
TForm1 =
class(TForm)
tvNav: TTreeView;
ActionList1: TActionList;
ActHilfe: TAction;
procedure FormCreate(Sender: TObject);
procedure ActHilfeExecute(Sender: TObject);
procedure tvNavMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
FTreeViewLocked: Boolean;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
Var
ANode : TTreeNode;
begin
ANode := tvNav.Items.AddChild(
nil, '
Erster');
tvNav.Items.AddChild(ANode, '
Erster U1');
tvNav.Items.AddChild(ANode, '
Erster U2');
tvNav.Items.AddChild(ANode, '
Erster U3');
tvNav.Items.AddChild(
nil, '
Zweiter');
with tvNav.Items.AddChild(
nil, '
Hilfe...')
do
Data := ActHilfe;
end;
procedure TForm1.ActHilfeExecute(Sender: TObject);
begin
ShowMessage('
Hilfe');
end;
procedure TForm1.tvNavMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var
ANode: TTreeNode;
R: TRect;
begin
// Navigator mit Click
// Doppelte Ausführung verhindern...
// FTreeViewLocked is Private Field der Unit!
if FTreeViewLocked
then
Exit;
FTreeViewLocked := True;
try
with TTreeView(Sender)
do
begin
ANode := GetNodeAt(x, y);
if Assigned(ANode)
and ANode.Selected
and Assigned(ANode.Data)
then
begin
R := ANode.DisplayRect(True);
// den Klick links oder rechts neben den Text verhindern
if (x >= R.Left - 16)
and (x <= r.Right)
then
if TObject(ANode.Data)
is TAction
then
TAction(ANode.Data).Execute;
end;
end;
finally
Application.ProcessMessages;
FTreeViewLocked := False;
end;
end;
end.