//==============================================================================
//数据集解构成树****************************************************************
//==============================================================================
procedure DataSetToTreeView(DataSet: TDataSet; var TreeView: TTreeView; NodeRoot: string);
var Nodes: array of TTreeNode;
Strs: array of string;
i: integer;
begin
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
with DataSet do
begin
Close;
Open;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SetLength(Nodes, FieldCount+1);
SetLength(Strs, FieldCount);
Nodes[0] := TreeView.Items.AddChild(nil, NodeRoot);
for i:=Low(Strs) to High(Strs) do Strs[i] := #255;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First;
while not Eof do
begin
for i:=Low(Strs) to High(Strs) do
if Strs[i]<>Fields[i].AsString then
begin
Strs[i] := Fields[i].AsString;
Nodes[i+1] := TreeView.Items.AddChild(Nodes[i],Fields[i].AsString);
end;
Next;
end;
Close;
end;
end;
theNode := TreeView1.TopItem.getFirstChild;
while (theNode.Text<>theStr) do
begin
if (theNode不是最后一个节点) then
theNode := theNode.GetNext
else
break;
end;
TheNode:=nil;
with TreeView.Items do for i:=0 to pred(Count) do
if Items[i].Text=DesireText then begin
TheNode:=Items[i];
break;
end;
if TheNode=nil then ShowMessage('Text not found')
else TheNode.MakeVisible(False);