procedure TForm2. TreeView1MouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var
TempNode: TTreeNode;
The begin
TempNode:=TreeView1 GetNodeAt (x, y);
If (TempNode<> Nil) and (TempNode=TreeView1. Selected) then
The begin
If treeview1. Items [0]. GetNext. Items [0]. The Selected then
The begin
Mainmenu1. Items [1] [0]. Click
The end;
The end;
The end;
Why tip list index out of bounds (0)??
CodePudding user response:
procedure TForm2. TreeView1MouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Var
TempNode: TTreeNode;
The begin
TempNode:=TreeView1 GetNodeAt (x, y);
If (TempNode<> Nil) and (TempNode=TreeView1. Selected) then
The begin
If treeview1. Items [0]. GetNext. Item [0]. The Selected then
The begin
Mainmenu1. Items [1] [0]. Click
The end;
The end;
The end;
CodePudding user response:
Source code is behind the haCodePudding user response:
Treeview subscript crossing the lineCodePudding user response:
I want to achieve what kind of function, is click on the inside of the treeview items and the mainmenu click events associated with?CodePudding user response:
The problems lie in the treeview1. Items [0]. GetNext. Item [0]. SelectedDescription:
A, A tree structure
Registration department
Internal medicine
Surgical
Eye
The doctor office
Office 1
Office 2
Office 3
Background management
The background 1
Background 2
The background of 3
Second, B tree structure
Registration department
Internal medicine
Internal medicine 1
Internal medicine 2
Internal medicine 3
Surgical
Eye
The doctor office
Office 1
Office 2
Office 3
Background management
The background 1
Background 2
The background of 3
Three, the analysis
1, treeview1 Items [0]. GetNext=treeview1. Items [1] for A tree is "internal" node
2, treeview1 Items [0]. GetNext. Item [0] for A tree is "internal" node of the first child node, A tree no children, cross mistakes
. 3, for B tree treeview1 Items. [0] GetNext. Item [0] is the child node 1: "internal" node "internal medicine 1", there will be no bounds error
Four, conclusion
Treeview1. Items [0]. GetNext. Item [0] is not a correct code, correct code regardless of tree structure, do not cross mistakes,