Forum Discussion
ajohnson2020
12 years agoContributor
I figured it out, in case anyone else needs to know. It is necessary to iterate through the row count of each tree level, checking the row count on the child views of each row and recursively going into them to retrieve the data. Code follows.
I haven't implemented data column restrictions yet, but that shouldn't be too difficult now that I've gotten this far.
Thanks.
Allen
procedure SaveTcxDBTree(TreeObject, oFile: OleVariant);
var rowloop, columnloop: integer;
rowstring, separator: string;
begin
// Iterate through each row of the top level of the tree
separator := '|';
for rowloop := 0 to TreeObject.wRowCount-1 do
begin
rowstring := '';
for columnloop := 0 to TreeObject.wColumnCount-1 do
begin
rowstring := rowstring + separator + VarToStr(TreeObject.wValue(rowloop, columnloop))
end;
oFile.Write(rowstring + #13#10);
// If this row has a child view with a one or more rows, call the same proc with the child
if TreeObject.wChildView(rowloop).wRowCount > 0 then
begin
SaveTcxDBTree(TreeObject.wChildView(rowloop), oFile);
end;
end;
end;
procedure WriteTreeToFile(TreeObject: OleVariant);
var inputstr, oFile;
begin
oFile := aqFile.OpenTextFile('C:\temp\output.txt', aqFile.faWrite, aqFile.ctANSI, true);
oFile.Write(inputstr);
SaveTcxDBTree(TreeObject, oFile);
oFile.Close;
end;
I haven't implemented data column restrictions yet, but that shouldn't be too difficult now that I've gotten this far.
Thanks.
Allen
procedure SaveTcxDBTree(TreeObject, oFile: OleVariant);
var rowloop, columnloop: integer;
rowstring, separator: string;
begin
// Iterate through each row of the top level of the tree
separator := '|';
for rowloop := 0 to TreeObject.wRowCount-1 do
begin
rowstring := '';
for columnloop := 0 to TreeObject.wColumnCount-1 do
begin
rowstring := rowstring + separator + VarToStr(TreeObject.wValue(rowloop, columnloop))
end;
oFile.Write(rowstring + #13#10);
// If this row has a child view with a one or more rows, call the same proc with the child
if TreeObject.wChildView(rowloop).wRowCount > 0 then
begin
SaveTcxDBTree(TreeObject.wChildView(rowloop), oFile);
end;
end;
end;
procedure WriteTreeToFile(TreeObject: OleVariant);
var inputstr, oFile;
begin
oFile := aqFile.OpenTextFile('C:\temp\output.txt', aqFile.faWrite, aqFile.ctANSI, true);
oFile.Write(inputstr);
SaveTcxDBTree(TreeObject, oFile);
oFile.Close;
end;