表
louno unitnoe2 1
e2 2
e2 3
e4 1
e5 1
e5 2欲显示为:
e2 1
2
3
e4 1
e5 1
2
源码:procedure TForm1.FormCreate(Sender: TObject);begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
with Query2 do
If Query2.Active then Query2.close;
Query2.sql.clear;
Query2.sql.add('select unitno from 表 group by unitno ');
Query2.open;
begin
Treeview1.Items.addchild(Treeview1.items.add(nil,query1['louno']) ,query2.fieldbyname('unitno').asstring);
end;
next;
end; end;
Query1.close;
Query2.close;
end;运行显示:
e2 1
e4 1
e5 1
上述源码如何修改?在线给分!!!!
louno unitnoe2 1
e2 2
e2 3
e4 1
e5 1
e5 2欲显示为:
e2 1
2
3
e4 1
e5 1
2
源码:procedure TForm1.FormCreate(Sender: TObject);begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
with Query2 do
If Query2.Active then Query2.close;
Query2.sql.clear;
Query2.sql.add('select unitno from 表 group by unitno ');
Query2.open;
begin
Treeview1.Items.addchild(Treeview1.items.add(nil,query1['louno']) ,query2.fieldbyname('unitno').asstring);
end;
next;
end; end;
Query1.close;
Query2.close;
end;运行显示:
e2 1
e4 1
e5 1
上述源码如何修改?在线给分!!!!
var louNO,i:integer; aNode:TTreeNode;
begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
louNO:= fieldbyname('louno').asInteger;
aNode:=Treeview1.items.add(nil,query1['louno']) ;
Query2.close;
Query2.sql.clear;
Query2.sql.add('select unitno from 表 where louno='+intToStr(louNO)+' order by unitno');
Query2.open;
while not Query2.eof do
begin
Treeview1.Items.addchild(aNode,query2.fieldbyname('unitno').asstring);
Query2.Next;
end;
Query1.Next;
end;
end;
Query1.close;
Query2.close;
end;
var v_louno:string;
begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
v_luono:=fieldbyname('louno').asstring;
treeview1.Items.AddChild(nil,v_luono);
with Query2 do
begin
close;
sql.clear;
sql.add('select distinct unitno from 表 where luono='''+v_louno+'''');
open;
while not eof do
begin
treeview1.Items.AddChild(nil,query2.fieldbyname('unitno').asstring);
next;
end;
query2.close;
end;
next;
end;
close;
end;
end;多給點分吧﹗
aNode:=Treeview1.items.add(nil,intToStr(louNO)) ; //与上面不同(2)Query2.sql.add('select unitno from 表 where louno='+intToStr(louNO)+' order by unitno');(3)Treeview1.Items.addchild(aNode,query2.fieldbyname('unitno').asstring);
procedure TForm1.FormCreate(Sender: TObject);
var louNO,i:integer; aNode:TTreeNode;
begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
louNO:= fieldbyname('louno').asInteger;
aNode:=Treeview1.items.add(nil,intToStr(louNO)) ;
Query2.close;
Query2.sql.clear;
Query2.sql.add('select unitno from 表 where louno='+intToStr(louNO)+' order by unitno');
Query2.open;
while not Query2.eof do
begin
Treeview1.Items.addchild(aNode,query2.fieldbyname('unitno').asstring);
Query2.Next;
end;
Query1.Next;
end;
end;
Query1.close;
Query2.close;
end;
你的显示:
e2
1
2
3
e4
1
e5
1
2不合要求?!
louno integer 问题我修改好了,run 显示e2 无默认值,如何修改!!
var v_louno:string;
node1:Ttreenode;
begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
v_luono:=fieldbyname('louno').asstring;
node1:=treeview1.Items.AddChild(nil,v_luono);
with Query2 do
begin
close;
sql.clear;
sql.add('select distinct unitno from 表 where luono='''+v_louno+'''');
open;
while not eof do
begin
treeview1.Items.AddChild(node1,query2.fieldbyname('unitno').asstring);
next;
end;
query2.close;
end;
next;
end;
close;
end;
end;現在行了吧。
多給點分吧﹗
var louNO:string; aNode:TTreeNode;
begin
with Query1 do
begin
close;
sql.clear;
sql.add('select louno from 表 group by louno');
open;
while not eof do
begin
louNO:= fieldbyname('louno').asString; //*************
aNode:=Treeview1.items.add(nil,louNO) ; //**************
Query2.close;
Query2.sql.clear; //***下面一句修改
Query2.sql.add('select unitno from 表 where louno='''+louNO+''' order by unitno');
Query2.open;
while not Query2.eof do
begin
Treeview1.Items.addchild(aNode,query2.fieldbyname('unitno').asstring);
Query2.Next;
end;
Query1.Next;
end;
end;
Query1.close;
Query2.close;
end;