Code snippet ...
|
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
begin
//populate the treeview control...
with treeview1.items do
begin
beginupdate;
for i := 1 to 2000 do
AddChild(nil, inttostr(i));
endupdate;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
//watch how this slows down as the loop proceeds...
//have a cup of tea handy if you have a slow processor :)
with treeview1 do
for i := 0 to items.count-1 do
begin
caption := items[i].Text;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
currentNode: TTreeNode;
begin
//by avoiding the relatively slow Items.Item[] property
//accessing individual treeview nodes can be very fast...
with treeview1 do
begin
currentNode := items.GetFirstNode;
while assigned(currentNode) do
begin
caption := currentNode.Text;
currentNode := currentNode.GetNext;
end;
end;
end;
|
|
|
|