My database is structured as follows:
UnitId UnitName
01 Chinese (root)
0101 Hebei (two trees)
010101 Cangzhou City (three trees) Hebei
01010101 Cangzhou City, Hebei Province, Cang County (four tree)
0102 in Beijing (two tree)
010201, Beijing (three trees), Haidian District
01020101 TangGuLing village, Haidian District, Beijing (four tree)
01,020,102 Haidian District, Dallas housing village (four tree)
010202 Chaoyang District, Beijing (three trees)
01,020,201 Beijing Chaoyang District Village (four tree)
0103 Tianjin (two trees)
010301 Dagang District (three trees)
01030101 Dagang District a place (four tree)
is a need for determining
when a length of 4 Unitid generating two tree
when Unitid length is 6 and the front 4 of length 4 Unitid three values are equal tree generated
when Unitid length is 8 and the length of the front 6 and 6 Unitid for generating four values are equal tree
brother novice, I do not know how to achieve the cycle. Please help. Thank you! ! !
procedure CreateTree;
const
ID_DEPT = 2;
var
nLevel: Integer;
pNodes: array[0..1023] of TTreeNode;
lpID, lpName: string;
begin
ADODataSet1.Close;
ADODataSet1.CommandText := 'SELECT * FROM [国家] ORDER BY [编号]';
ADODataSet1.Open;
pNodes[0] := nil;
TreeView1.Items.Clear;
with ADODataSet1.Recordset do
while not Eof do
begin
lpID := Fields['编号'].Value;
lpName := Fields['名称'].Value;
nLevel := Length(lpID) div ID_DEPT;
pNodes[nLevel] := TreeView1.Items.AddChild(pNodes[nLevel - 1], lpName);
MoveNext;
end;
end;