虽然我刚学习DELPHI,但好象方向也没错呀。。。看我写的一个实际用的例程,请对DELPHILAI的看法不以为然的朋友给提提意见(branchno 是我用来区别不同分公司的用户的
procedure TForm1.btnLookClick(Sender: TObject);
begin
TreeLook.items.clear;
with tmpquery do
begin
close;
sql.clear;
sql.text:='select * from codetree where BranchNo='''+branchno+''' order by treelevel,fathersxh,sxh ' ;
open;
first;
FatherNode:=Nil;
Fathersxh:=0 ;
while not eof do
begin
NowFathersxh:=FieldbyName('FatherSxh').asinteger;
//是否要重新查找父节点
if NowFatherSxh<>FatherSxh then
begin
loopi:=0;
while Pnode(treelook.items[loopi].data)^.sxh<>NowFatherSxh do inc(loopi);
Fathersxh:=NowFatherSxh;
FatherNode:=treelook.items[loopi];
end;
//生成节点数据 并作为其父亲的子节点加入
new(node0);
node0^.sxh:=fieldbyname('sxh').asinteger;
node0^.branchno:=fieldbyname('branchno').asstring ;
treelook.items.addchildobject(FatherNode,fieldbyname('nodename').asstring,node0);
next;
end ;
end;
end;
表结构
CREATE TABLE CODETREE (
SXH INTEGER NOT NULL,
FATHERSXH INTEGER,
SONNODE INTEGER,
NODENAME CHAR(40),
BRANCHNO CHAR(6),
TREELEVEL INTEGER DEFAULT 0 NOT NULL,
)
SXH是表的首键,