Autor Beitrag
jcop
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Fr 04.09.09 08:37 
Hi

I have declared following pointer.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
type
    Pacft = ^Tacft;
     Tacft = record
          Title : string;
          Sim : String;
          texture: String;
          Model : string;
          atc_airline : string;
          ui_manufacturer : string;
          FolderPath : string;
          FltSimID: Integer;

    end;

After I have runned a load
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
acftpath := ExtractFileDir(ANAME);
  delete(acftpath, 1, (fspathint + 1));

  node := Treeview1.Items.Add(nil, acftPath);
  acft := Tinifile.Create(Aname);

  try
   i := 0;
   repeat
    begin
    new (MyPacft);
    MyPacft^.Title := acft.ReadString('fltsim.' + intToStr(i), 'Title', 'EMPTY');
    MyPacft^.Sim := acft.ReadString('fltsim.' + intToStr(i), 'SIM', 'EMPTY');
    MyPacft^.texture := acft.ReadString('fltsim.' +intToStr(i), 'Texture', 'EMPTY');
    MyPacft^.Model := acft.ReadString('fltsim.' + intToStr(i), 'MODEL', 'EMPTY');
    MyPacft^.atc_airline := acft.ReadString('fltsim.' + intToStr(i),'act_airline', 'EMPTY');
    MyPacft^.ui_manufacturer := acft.ReadString('fltsim.' + intToStr(i), 'ui_manufacturer', 'EMPTY');
    MyPacft^.FolderPath := AName;
    MyPacft^.FltSimID := i;

    acftTitleNode := TreeView1.Items.addchildObject(node, MyPacft^.Title, MyPacft);


    i := i + 1;
    End;
   until acft.SectionExists('fltsim.' + intToStr(i)) = False;
  finally
   acft.Free;
   Y := Y + I;

  end;

I want to have the total of subnodes that I added. For I was thinking of using the value of I after each until "acft.SectionExists('fltsim.' + intToStr(i)) = False;" procedure and count copy this value to another integer, but it always gives me the same number that I holds. Can somebody help me and explain what I'm doing wrong?

regards
Johan

Moderiert von user profile iconNarses: Quote- durch Delphi-Tags ersetzt
Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Fr 04.09.2009 um 10:21
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Fr 04.09.09 12:22 
How about using TTreeView.count?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
oldcount:=treeview1.Items.Count;
// adding Nodes
newcount:=treeview1.Items.Count;

NodesAdded:=newcount-oldcount;


I hope this helps.
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Fr 04.09.09 14:12 
user profile iconTilo hat folgendes geschrieben Zum zitierten Posting springen:
How about using TTreeView.count?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
oldcount:=treeview1.Items.Count;
// adding Nodes
newcount:=treeview1.Items.Count;

NodesAdded:=newcount-oldcount;


I hope this helps.


Yes I saw that one also, but this is counting all nodes I only want to count the SubNodes.

but thanks for the reply.

rgds,
Johan
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 04.09.09 14:42 
user profile iconjcop hat folgendes geschrieben Zum zitierten Posting springen:
Yes I saw that one also, but this is counting all nodes I only want to count the SubNodes.

Heh, then just do that:
ausblenden Delphi-Quelltext
1:
node.Count					

is what you may be looking for.

HTH,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 07.09.09 07:23 
Hi,

Also the nodes.count didn't solved this, but I was able to solve it, below is the code I used.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm5.Button1Click(Sender: TObject);
var
  i, cnt, x: integer;
  Nodes: TTreenodes;

BEGIN
  X := 0;
  i := 0;

  BEGIN
 for cnt := 0 to treeview1.Items.Count - 1 do
    if treeview1.Items[x].Level = 1 then
    begin
    inc(i);
    x := x + 1;
    end
    else
    begin
    x := x + 1;
    end;
END;
showmessage(IntTostr(i));
END;


I hope the above code is good, but if somebody comes up with an easier/shorter way please let me now.
Now the only thing I have to manage is create a procedure for this so I can call this everytime
something changes in the treeview.

thanks for all your suggestions.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 07.09.09 08:21 
What about x, why is it there? It always has the same value as your loop variable as you increase it always. The same what you did looks like this if you make the code a bit shorter:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm5.Button1Click(Sender: TObject);
var
  i, cnt: integer;
begin
  cnt := 0;
  for i := 0 to TreeView1.Items.Count - 1 do
    if TreeView1.Items[i].Level = 1 then
      Inc(cnt);
  ShowMessage(IntToStr(cnt));
end;
jcop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27

WinXP, Vista
Delphi 2009, Vb.NET
BeitragVerfasst: Mo 07.09.09 08:40 
jaenicke,

Thanks for this, indeed shorter, I was thinking that for each item in de treeview I also had to increase the itemnumber, that why I created the X.

regards,
Johan