with TQuery.Create(Self) do
begin
DatabaseName := 'BDETable';
SQL.Add('select * from Area');
SQL.Add('where LEN(AreaID) = :AreaLen');
SQL.Add('order by AreaID');
ParamByName('AreaLen').AsInteger := 2;
Open();
while not(Eof) do
begin
tmpNode := ZoneTree.Items.Add(nil, FieldByName('Area').AsString);
new(AreaData);
AreaData.ID := FieldByName('AreaID').AsString;
AreaData.Len := 2;
tmpNode.Data := AreaData;
Next();
end;
Close();
for i := 2 to 5 do
begin
ParamByName('AreaLen').AsInteger := i * 2;
Open();
while not(Eof) do
begin
tmpNode := nil;
for j := ZoneTree.Items.Count - 1 downto 0 do
begin
AreaData := ZoneTree.Items[j].Data;
if Copy(FieldByName('AreaID').AsString, 1, AreaData.Len) = AreaData.ID then
begin
tmpNode := ZoneTree.Items[j];
Break;
end;
end;
tmpNode := ZoneTree.Items.AddChild(tmpNode, FieldByName('Area').AsString);
new(AreaData);
AreaData.ID := FieldByName('AreaID').AsString;
AreaData.Len := i * 2;
tmpNode.Data := AreaData;
Next();
end;
Close();
end;
Free();
end;