treeview中前面都是父节点,只有到了第5个才是子节点,程序只需要从第5个开始选中,listview才显示相关的数据,且数据是从两个表中导出,以下的代码如下,但是不行,我不知错在那里,有那位高手可否指点一二,在此先行谢过。
procedure Tmainpagefrm.TreeView1Changing(Sender: TObject; Node: TTreeNode;
  var AllowChange: Boolean);
  var
  titem:tlistitem;
  n:integer;
begin
with mindatamodule.adotgp,mindatamodule.adoqrycustlist,listview1 do
begin
if treeview1.Selected.AbsoluteIndex>4 then
sql.Clear;
sql.Add('select tcustomer.cust_no,tcustomer.cust_name,tcustomer.cust_bp,tcustomer.bp_code,tcustomer.bp_type,tcustomer.reg_date,tcustomer.unreg_date,tcustomer.mobile,tcustomer.email from tgp_cust,tcustomer where tgp_cust.cust_no=tcustomer.cust_no and tgp_cust='+quotedstr(node.Text));
open;
listview1.Clear;
repeat
   n:=n+1;
   titem:=listview1.Items.Add;
   titem.Caption:=inttostr(n);
   titem.SubItems.Add(fieldbyname('cust_no').AsString );
   titem.SubItems.Add(fieldbyname('cust_name').AsString);
   titem.SubItems.Add(fieldbyname('cust_bp').AsString);
   titem.SubItems.Add(fieldbyname('bp_code').AsString);
   titem.SubItems.Add(fieldbyname('bp_type').AsString);
   titem.SubItems.Add(fieldbyname('reg_date').AsString);
   titem.SubItems.Add(fieldbyname('unreg_date').AsString);
   titem.SubItems.Add(fieldbyname('mobile').AsString);
   titem.SubItems.Add(fieldbyname('email').AsString);
   next;
   until
   eof;
end;
end;
end.

解决方案 »

  1.   

    提示什么?另外你的循环写的不正确while 和repeat的区别是什么不用再说了吧
      

  2.   

    是提示tgp_cust.cust_no这个列名错误,但adoquery的连接和设置没有发现错误,是不是sql语句的语法有问题,我不是很清楚
      

  3.   

    where tgp_cust.cust_no=tcustomer.cust_no and tgp_cust='+quotedstr(node.Text));///////////////////////////////////////////
    tgp_cust='+quotedstr(node.Text));tgp_cust是表名?
      

  4.   

    是的,tgp_cust是表名来的,是我漏了字段名,字段名为cust_name(tgp_cust.cust_name),但是在运行时提示在tgp_cust.cust_name=后即有错误,不知是否为语法错误,至于楼上讲的用while,来代替repeat,好像不行,我一用程序即死了,所以我还是用回repeat.