sorry,我再解释一下吧,程序是这样的:表里的FIELD是A1,A2,A3,A4..A30
A1----YEAR 2002、2003.....
A2----MONTH 01....12
A3----LINE_NO 1...20
A4..A30 --数据
每年每月有20条数据,但年和月即A1,A2都是一样的
要求按年生成PARENT,按月生成CHILD对应年
我的程序是这样的,但是有点小问题
var node:ttreenode;
tempstring:string;
i,j:integer;
begin
with query1 do
begin
close;
sql.add('select distinct a1 from table');
sql.add('where A3=:lineno');
parambyname('lineno').asstring:='15';
prepare;
open;
end;
for i:=1 to query1.recordcount do
begin
if not query1.eof then
begin
tempstring:=query1.fieldbyname('a1').asstring;
query1.next;
if query1.fieldbyname('a1').asstring<>tempstring then
begin
node:=Items.Add(nil,tempstring);
end;
end
else
begin
node:=items.add(nil.tempstring);
end;
with Query2 do
begin
close;
sql.clear;
sql.add('select distinct A2 from table');
sql.add('where (a1=:lineno) and (B0=:query1a1)');
parambyname('lineno').asstring:='15';
parambyname('query1a1').asstring:=query1.fieldbyname('a1').asstring;
prepare;
open;
end;
for j:=1 to query2.recordcount do
begin
Items.AddChild(node,Query2.FieldbyName('a2').asstring);
query2.Next;
end;
end;