procedure ZsDataSetToTreeView(mDataSet: TDataSet;
mTreeView: TTreeView);
{ 将数据源转换成可视树 }
type
TArrayTreeNode = array of TTreeNode;
var
vFieldCount: Integer;
vStringList: TStringList;
procedure pZsDataToTreeNode(mArrayTreeNode: TArrayTreeNode;
mIndex: Integer;
mValueList: string);
var
vTreeNode, vTempTreeNode: TTreeNode;
vStr, S, vTemp: string;
I: Integer;
vArrayTreeNode: TArrayTreeNode;
begin
vTemp := mValueList;
vStringList.Text := mValueList;
vStr := #13#10;
vTreeNode := nil;
if mIndex < vStringList.Count then
begin
if (Pred(mIndex) >= Low(mArrayTreeNode)) and (Pred(mIndex) < High(mArrayTreeNode))then
vTreeNode := mArrayTreeNode[Pred(mIndex)];
vStr := vStringList[mIndex];
end;
vArrayTreeNode := mArrayTreeNode;
with mDataSetdo
while not Eofdo
begin
S := FieldByName(FieldDefs[mIndex].Name).AsString;
if (vStr = #13#10) or (vStr <> S) or (mIndex = Pred(vFieldCount)) then
begin
vTreeNode := mTreeView.Items.AddChild(vTreeNode,
FieldByName(FieldDefs[mIndex].Name).AsString);
vStr := S;
vTempTreeNode := vTreeNode;
SetLength(vArrayTreeNode, vFieldCount);
vArrayTreeNode[mIndex] := vTempTreeNode;
for I := Succ(mIndex) to Pred(vFieldCount)do
begin
vTempTreeNode := mTreeView.Items.AddChild(vTempTreeNode,
FieldByName(FieldDefs.Name).AsString);
vArrayTreeNode := vTempTreeNode;
end;
vStringList.Clear;
for I := 0 to Pred(vFieldCount)do
vStringList.Add(FieldByName(FieldDefs.Name).AsString);
vTemp := vStringList.Text;
Next;
pZsDataToTreeNode(vArrayTreeNode, 0, vTemp);
vArrayTreeNode := nil;
end else
begin
pZsDataToTreeNode(vArrayTreeNode, Succ(mIndex), vTemp);
end;
end;
end;
begin
vStringList := TStringList.Create;
mTreeView.Items.Clear;
vFieldCount := mDataSet.FieldCount;
mDataSet.First;
pZsDataToTreeNode(nil, 0, '');
vStringList.Free;
end;
{ ZsDataSetToTreeView }