L
lili365
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的代码看出有什么不足吗,我执行时老报‘Unable to insert an item’,我跟踪时
发现是Form1.TreeView1.Items.AddChild(TTreeNode(Node.CardType),Node1^.Name)的问题
procedure BuildTree(trv:TTreeView);
Var
TmpSql,NodeSql:String;
last:String;
// Current:TTreeNode;
Node1:^TMyStructure;
Begin
If Form1.ADOQuery1.State<>dsInactive then Form1.ADOQuery1.Close;
// Current:=nil;
With Form1.ADOQuery1 Do
Begin
Sql.Clear;
TmpSql:='Select CardType,Father,Name From CardType Where Father is null';
Sql.Add(TmpSql);
Open;
First;
While Not Eof Do
Begin
New(Node);
Node^.Cardtype:=FieldValues['CardType'];
Node^.Father:=FieldValues['Father'];
Node^.Name:=FieldValues['Name'];
// last:=FieldValues['CardType'];
Form1.TreeView1.Items.AddObject(nil,Node^.Name,Node);
If Form1.ADOQuery2.State<>dsInactive then Form1.ADOQuery2.Close;
With Form1.ADOQuery2 Do
Begin
NodeSql:='Select CardType,Father,Name From CardType Where Father='''+Node^.Cardtype+'''';
Sql.Add(NodeSql);
open;
First;
While not Eof Do
Begin
New(Node1);
Node1^.Cardtype:=FieldValues['CardType'];
Node1^.Father:=FieldValues['Father'];
Node1^.Name:=FieldValues['Name'];
Form1.TreeView1.Items.AddChild(TTreeNode(Node.CardType),Node1^.Name);
Next;
End;
Close;
End;
Next;
End;
End;
End;
发现是Form1.TreeView1.Items.AddChild(TTreeNode(Node.CardType),Node1^.Name)的问题
procedure BuildTree(trv:TTreeView);
Var
TmpSql,NodeSql:String;
last:String;
// Current:TTreeNode;
Node1:^TMyStructure;
Begin
If Form1.ADOQuery1.State<>dsInactive then Form1.ADOQuery1.Close;
// Current:=nil;
With Form1.ADOQuery1 Do
Begin
Sql.Clear;
TmpSql:='Select CardType,Father,Name From CardType Where Father is null';
Sql.Add(TmpSql);
Open;
First;
While Not Eof Do
Begin
New(Node);
Node^.Cardtype:=FieldValues['CardType'];
Node^.Father:=FieldValues['Father'];
Node^.Name:=FieldValues['Name'];
// last:=FieldValues['CardType'];
Form1.TreeView1.Items.AddObject(nil,Node^.Name,Node);
If Form1.ADOQuery2.State<>dsInactive then Form1.ADOQuery2.Close;
With Form1.ADOQuery2 Do
Begin
NodeSql:='Select CardType,Father,Name From CardType Where Father='''+Node^.Cardtype+'''';
Sql.Add(NodeSql);
open;
First;
While not Eof Do
Begin
New(Node1);
Node1^.Cardtype:=FieldValues['CardType'];
Node1^.Father:=FieldValues['Father'];
Node1^.Name:=FieldValues['Name'];
Form1.TreeView1.Items.AddChild(TTreeNode(Node.CardType),Node1^.Name);
Next;
End;
Close;
End;
Next;
End;
End;
End;