悬赏捉拿算法高手(1000大洋)(300分)

  • 主题发起人 主题发起人 szhhp
  • 开始时间 开始时间
function InitLPartitionTreeView(TreeView : TTreeView; ClientDataSet, ClientDataSet1, ClientDataSet2, ClientDataSet3, ClientDataSet4 : TClientDataSet) : Integer;
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNode5 : TTreeNode ;
i1, i2, i3, i4, i5, NcubeCount : Integer ;
PTypeAndID : PointTypeAndID;
begin
NcubeCount := 0;
with TreeView.Items do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'MPEGFILE_MANAGE';
PTypeAndID^.TypeID := '';
TreeNode := AddChildObject(nil, '节目源', PTypeAndID);
TreeNode.ImageIndex := ICO_MPEGFILE_MANAGE;
TreeNode.SelectedIndex := ICO_MPEGFILE_MANAGE;

with ClientDataSet do
begin
Close ;
CommandText := 'Select * From LOCATION_Code Where LEVEL_ID=3 ORDER BY LOCATION_NAME' ;
Open ;
for i1 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'FIRST_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode1 := AddChildObject(TreeNode, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode1.ImageIndex := ICO_FRIST_LOCATION;
TreeNode1.SelectedIndex := ICO_FRIST_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where CATEGORY_ID = ''VOD'' AND LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode1, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
with ClientDataSet1 do
begin
Close ;
CommandText := Format('Select * From LOCATION_Code Where LEVEL_ID=2 and UPPERLOCATION_ID=''%s'' ORDER BY LOCATION_NAME',[ClientDataSet.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i2 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'SECOND_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode2 := AddChildObject(TreeNode1, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode2.ImageIndex := ICO_SECOND_LOCATION;
TreeNode2.SelectedIndex := ICO_SECOND_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet1.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode2, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
with ClientDataSet2 do
begin
Close ;
CommandText := Format('Select * From LOCATION_Code Where LEVEL_ID=1 and UPPERLOCATION_ID=''%s'' ORDER BY LOCATION_NAME',[ClientDataSet1.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i3 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'THIRD_LOCATION';
PTypeAndID^.TypeID := FieldByName('LOCATION_ID').AsString;
TreeNode3 := AddChildObject(TreeNode2, FieldByName('LOCATION_NAME').AsString, PTypeAndID);
TreeNode3.ImageIndex := ICO_THIRD_LOCATION;
TreeNode3.SelectedIndex := ICO_THIRD_LOCATION;
with ClientDataSet3 do
begin
Close ;
CommandText := Format('Select * From DEVICE_CODE Where LOCATION_ID=''%s'' ORDER BY DEVICE_NAME',[ClientDataSet2.FieldByName('LOCATION_ID').AsString]) ;
Open ;
for i4 := 0 to RecordCount - 1 do
begin
NcubeCount := NcubeCount + 1;
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_CODE';
PTypeAndID^.TypeID := FieldByName('DEVICE_ID').AsString;
TreeNode4 := AddChildObject(TreeNode3, FieldByName('DEVICE_NAME').AsString, PTypeAndID);
TreeNode4.ImageIndex := ICO_DEVICE_CODE;
TreeNode4.SelectedIndex := ICO_DEVICE_CODE;
with ClientDataSet4 do
begin
Close ;
CommandText := Format('Select * From DEVICE_LPARTITION Where DEVICE_ID=''%s'' ORDER BY LOGICAL_PARTITION',[ClientDataSet3.FieldByName('DEVICE_ID').AsString]) ;
Open ;
for i5 := 0 to RecordCount - 1 do
begin
New(PTypeAndID);
PTypeAndID^.TypeType := 'DEVICE_LPARTITION';
PTypeAndID^.TypeID := FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString;
PTypeAndID^.TypeID1 := ClientDataSet3.FieldByName('DEVICE_ID').AsString;
TreeNode5 := AddChildObject(TreeNode4, FieldByName('LOGICAL_PARTITION').AsString + FieldByName('DELIMITER').AsString, PTypeAndID);
TreeNode5.ImageIndex := ICO_DEVICE_LPARTITION;
TreeNode5.SelectedIndex := ICO_DEVICE_LPARTITION;
ClientDataSet4.Next;
end;
end;
ClientDataSet3.Next;
end;
end;
ClientDataSet2.Next;
end;
end;
ClientDataSet1.Next;
end;
end;
ClientDataSet.Next;
end;
end;
end ;
Result := NcubeCount;
end;

{ InitLPartitionTreeView
TreeView TTreeView 存放所有节目单和节目源元素
ClientDataSet,ClientDataSet1, ClientDataSet2, ClientDataSet3, ClientDataSet4 : TClientDataSet
返回值 Integer NCUBE的数量 。
var
TreeNode, TreeNode1, TreeNode2, TreeNode3, TreeNode4, TreeNode5 : TTreeNode ;
//六层的TreeView的每一级 元素
i1, i2, i3, i4, i5 : Integer
//循环用
NcubeCount : Integer
//NCUBE的数量
PTypeAndID : PointTypeAndID;
//为TreeView 指向的指针类型}
 
我想还是递归比较好:
procedure button1Click(Sender: Object);
begin
ClientDataSet1.Filter := '父项目ID=''*''';
ClientDataSet1.Filtered := true;
while not ClientDataSet1.Eof do
begin
node := TreeView1.Add(nil,ClientDataSet1.FieldByName('项目名称').AsString);
BuildTree(node,ClientDataSet1.FieldByName('项目ID').AsString);
ClientDataSet1.Next;
end;
end;

procedure buildTree(node: TreeNode; id: String);
var
cds: TClientDataSet;
cnode: TTreeNode;
begin
cds := TClientDataSet.Create(Self);
try
cds.CloneCursor(ClientDataSet1,false);
cds.Filter := '父项目ID=''' + id + '''';
cds.Filtered := true;
while not cds.Eof do
begin
cnode := TreeView1.Items.AddChild(node,cds.FieldbyName('项目名称').AsString);
buildTree(cds.FieldbyName(cnode,'项目ID').AsString);
cds.Next;
end;
except
end;
cds.Free;
end;
 
跟我的超级光盘管家一样,呵呵,提示,不要一次全部加载,需要时才加载孙节点部份。
 
能不用递归的还是尽量不用的好,递归效率太低:)
jsxjd的不错:)
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部