TREE VIEW - display

Please discuss general Delphi programming topics here.

TREE VIEW - display

Postby sekar1 » February 6th, 2007, 11:51 am

i am using the tree view for reading and displaying the data read from the file.. the file contains group and sub groups (Many).. i read the data and stored the name and data in the seperate arrays.the problem is how should i show the subgroups and goups name in the tre view?
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Kambiz » February 6th, 2007, 6:13 pm

Have you ever tried to click on a TreeView control on a form and then press F1?
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby sekar1 » February 8th, 2007, 8:33 am

Ya.. i tried but the thing is that my problem is of something like this.. in a file there is no of groups and in each groups there are no of sub groups Example:(customer database(Name) -> Yearly(nearly five year) -> monthly( 12 monthsfor each year) .. i need to develop a code which will allocate the names, year and in each year every month in the treenode automatically... i am wrestling for this nearly more than a week... can anyone send the solution r suggest some valuable ideas which will be positive to the solution?
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Kambiz » February 8th, 2007, 2:19 pm

You can use the following set of functions as a template.

Code: Select all
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;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby sekar1 » February 13th, 2007, 5:22 am

thanx for your help
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Reg writing a ascii file

Postby sekar1 » February 26th, 2007, 5:35 am

hi kambiz,

thanks for your great support in writing the code for my application.. now, iam developing the code to create a file in ascii format from a already stored recored.. the file should be look like a table.. name, decription, quantity like this, there much be around 1000 to some ten thousand elements set in the record.. the problem i am facing is to set the space constraints between the two variable while writing..

for ex i am writing the one line of the ouptu file in normal format..
Code: Select all
Si.No---Name------Xvalue----------Yvalue-----------Yunit------Time

1.-------Grid--------0.001254896---180.1245698----Watts-----20/2/2007


like this the line(--- space tabs) should be of aligned as a uniform column. the problem is some data is having 4 decimal values and some other is having 12 decimal values.. i am facing problem in using character strings(#13) that i tried.

please give some suggestions to solve this.. i tried in help also but finding any good solutions..

//EDIT by J_B: use the code Luke! And whatever browser you use, make sure it has Dictionary... I won't fix it for you.
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Kambiz » February 26th, 2007, 9:46 am

Look for Write procedure in Delphi help.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Reg: treeview

Postby sekar1 » April 10th, 2007, 2:10 pm

hi kambiz,

reg the treeview that i asked early, i av some doubts.

i created the treeview component in main class. i stored the data as seperate classes in another file(.pas file).. can i call the main class inside this one and declared the treeview function. if i want to do means i need to declare the main class as an object in another file.. i tried in normal way.. but it shows some error...

the main thing is that i declared the database name and other variable as private in seperate class and i created property to access the variable..

can u suggest some way..
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Johnny_Bit » April 10th, 2007, 3:12 pm

by all means, may I?

Firs of all, the fault is yours, you simply use OOP improperly.
Second, "but it shows some error..." well, I've got some fix.
Third, I've read through your post several times and still I don't get it.
Last but not least, firefox with spellcheck, plz.

I suggest you to clarify what you want to do when you want to get decent answer.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron