不好意思阿,大侠,我也没有斗气的想法。别见怪。呵呵。Node.HasChildren := FieldByName('ISEND').AsInteger = 0; //加载子结点时是否有孙子结点是判断过的。数据表中有一个字段来区别是否是末级。procedure LoadTreeCurrentNode(id: string); //ID是单击时选中的结点的一个编号var Parent, Node: TTreeNode; Level: integer;begin if TreeView1.Selected.Count > 0 then Exit; //有孩子就不再展了 Parent := TreeView1.Selected; Level := Length(id) - Length(StringReplace(StringReplace(id, '$', '-', [rfreplaceall]), '-', '', [rfreplaceall])) + 1; with TmpQuery do begin Close; Connection := zs_dm.ado_xm; Sql.Clear; Sql.Add('select lxmc10 as id,xm2,gcode,case when level = (select level from (select max(level) as level from table1 where (level <> 66 and level <> 99) and lxmc10 like ''' + id + '%'') a ) then 1 else 0 end as isend from l_table1 _km where lxmc10 like ''' + id + '%'' and len(lxmc10)- len(replace(replace(lxmc10,''$'',''-''),''-'',''''))= ' + inttostr(Level) + ' order by lxmc10 asc '); try Open; except end; if IsEmpty then begin Exit; end; while not Eof do begin New(Mytreenode); Mytreenode^.id := FieldbyName('id').AsString; Mytreenode^.xm2 := FieldbyName('xm2').AsString; Mytreenode^.gcode := FieldbyName('gcode').AsString; Node := TreeView1.Items.AddChildobject(Parent, Mytreenode^.xm2, Mytreenode); Node.HasChildren := FieldByName('ISEND').AsInteger = 0; Next; end; end;end;