看看这个‘天杀的’(100分)

  • 主题发起人 主题发起人 lili365
  • 开始时间 开始时间
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;
 
我感觉是TTreeNode(Node.CardType)的错误,明明不是TTreeNode类型,硬是强换也不行的。
 
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'];


//////////////////////////////////
Current:=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(Current,Node1^.Name);
////////////////////////////////////////////////////////////////////////////////

Next;
End;

Close;

End;
Next;

End;

End;
End;
 
谢谢aizb,有时间再看看跟这个有关的“谁来看看这个‘杂碎’”,问题是当我关闭窗口时
由于没有释放掉所占的内存,产生异常,我如何去做,针对上面的代码,给个例子
 
后退
顶部