Can someone advise me on how I should be adding child nodes to a standard
Ttreeview control in Delphi 2006?
Briefly, I am trying to look at a series of files, extracting elements of
data from them and building a tree of these elements.
My code works fine with the first file but I am finding that the elements of
the first file I have extracted are also appearing in the nodes of
subsequent files. See attached screenshot - the items enclosed in the
rectagle only apply to the first file (SPI) and only the last item in the
list should apply to the second file (spiEEPROM).
This is an extract of the code I am using: - I have highlighted the lines
which reference the Ttreeview control.
for i := 0 to filelist.Count -1 do
begin
SourceText.LoadFromFile(FileList[i]);
.
.
.
s := ExtractFileName(FileList[i]); // extract name
s := leftStr(s, length(s)-4); // and remove extension
> Node := tLibExplorer.Items.Add(nil,s); // create new node in
ExplorerTree
.
.
.
// Add a new set of sub nodes for this library
> NodeVars := tLibExplorer.Items.AddChild(Node,'Vars');
// search for Public subs, functions, Vars and constants
j := 0;
while j < sourcetext.Count -1 do
begin
// Check for Public Dims
if ANSIStartsText('Public Dim',Trim(SourceText[j])) then
begin
tempStr := trim(RightStr(SourceText[j],Length(SourceText[j])
-10));
If Length(TempStr) < 11 then
begin
Inc(j);
tempstr := Trim(SourceText[j]);
dimlist.Add(s + tempStr);
> tLibExplorer.Items.AddChild(NodeVars,tempStr);
end;
While ANSIEndsText(',', TempStr) do
begin
inc(j);
tempStr := Trim(SourceText[j]);
if tempStr = '' then continue;
> tLibExplorer.Items.AddChild(NodeVars,tempStr);
dimList.Add(s + tempStr);
end;
end;
inc(j);
end;
end;
I know my extraction logic is correct as I am loading the data into a string
list as well just to check. It seems that when I add the child items they
get copied to all nodes although I am updating the node value when I
generate the next main node and first child node.
What am I doing wrong?
John Barrat
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi