function FindNode(Tree: TTreeView; const Name: String; Year, Month: Word): TTreeNode;
function FindChild(Parent: TTreeNode; const Target: String): TTreeNode;
var
I: Integer;
begin
Result := Parent;
for I := 0 to Parent.Count - 1 do
if SameText(Parent.Item[I].Text, Target) then
begin
Result := Parent.Item[I];
Exit;
end;
end;
var
I: Integer;
begin
Result := nil;
for I := 0 to Tree.Items.Count - 1 do
if SameText(Tree.Items[I].Text, Name) then
begin
Result := FindChild(Tree.Items[I], IntToStr(Year)); // Look for year
if Result.Level = 1 then // Year is found
Result := FindChild(Result, IntToStr(Month)); // Look for month
Exit;
end;
end;
function AddToTree(Tree: TTreeView; const Name: String; Year, Month: Word): TTreeNode;
begin
Result := FindNode(Tree, Name, Year, Month);
if not Assigned(Result) then
Result := Tree.Items.AddChild(nil, Name);
if Result.Level = 0 then
Result := Tree.Items.AddChild(Result, IntToStr(Year));
if Result.Level = 1 then
Result := Tree.Items.AddChild(Result, IntToStr(Month));
end;
procedure BuildTree(Tree: TTreeView; Table: TTable);
var
Name: String;
Year, Month, Day: Word;
begin
Tree.Items.BeginUpdate;
try
Tree.Items.Clear;
Table.First;
while not Table.Eof do
begin
// Retrieve name and date
Name := Table.FieldValues['Name'];
DecodeDate(Table.FieldValues['Date'], Year, Month, Day);
with AddToTree(Tree, Name, Year, Month) do
begin
// customize the new node
Text := Table.FieldValues['Description'];
end;
Table.Next;
end;
Tree.AlphaSort;
finally
Tree.Items.EndUpdate;
end;
end;
Si.No---Name------Xvalue----------Yvalue-----------Yunit------Time
1.-------Grid--------0.001254896---180.1245698----Watts-----20/2/2007
Users browsing this forum: No registered users and 14 guests