Та же проблема.
Из процедуры:
Код:
Select -g.GroupID,
null as Parent,
g.GroupCode,
g.GroupName
From Group g -- группа
UNION ALL
Select sg.SubGroupID as GroupID,
-wg.GroupID as Parent,
sg.SubGroupCode as GroupCode,
sg.SubGroupName as GroupName
From SubGroup sg -- подгруппа
нужно построить дерево в TreeView.
Я использую следующий код:
Код:
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
try
// получение набора данных ADOStoredProc
except
//
end;
// строим дерево
ADOStoredProc.First;
TreeView.Items.AddObject(nil, ADOStoredProc['GroupName'],
Pointer(Integer(ADOStoredProc['GroupID'])));
ADOStoredProc.Next;
while not ADOStoredProc.Eof do
begin
i:=0;
while i < TreeView.Items.Count do
begin
if TreeView.Items.Item[i].Data =
Pointer(Integer(ADOStoredProc['Parent'])) then
TreeView.Items.AddChildObject(TreeView.Items.Item[i],
ADOStoredProc['GroupName']),
Pointer(Integer(ADOStoredProc['GroupID'])))
else
Inc(i);
ADOStoredProc.Next;
end;
end;
end;
Все бы ничего, но дерево почему-то состоит из одной веточки.
Помогите найти ошибку.