I have a form with a treeview and 2 buttons
On the forms OnCreate event, an XML file is loaded into the treeview
The code is timed and displayed in the statusbar1.Panels[0]
Clicking the first button clears the treeview, this code is also timed and is displayed in the statusbar1.Panels[1]
Clicking the second button reloads the XML file into the treeview
Again, the code is timed and is displayed in the statusbar1.Panels[2]
The timings for the loading, clearing and reloading are :
1220 verbs : 0,378 seconds
Cleared in : 13,7 seconds
1220 verbs : 0,972
Obviously, there is a few milliseconds difference each time I run the program
My question is why does it take almost 14 seconds to clear the treeview. If I just close the form by clicking the X in the top right hand corner, Delphi closes normally after freeing memory, cleaning up etc. in 1 or 2 seconds.
I don't need to clear the data in my project, I'm curious to know what delphi is doing for 14 seconds.
The code for the form OnCreate event and the reload button is the same except for the statusbar1.Panels
The clear treeview code is just
TreeView1.Items.Clear;
with the timing code.
I like your site - it has a clean and simple layout. I hope to use your MRU code in this project of mine. At the moment, I am playing around with Delphi whilst learning BDS 2006
Thanks for and help in advance but again, it is not important, I'm just curious
- Code: Select all
procedure TForm4.FormCreate(Sender: TObject);
var
pList: IXMLTree2xmlType;
i: integer;
aTreeNode: TTreeNode;
Freq, StartCount, StopCount: Int64;
TimingSeconds: double;
begin
pList := Gettree2xml(XMLDocument1);
TreeView1.Items.BeginUpdate;
QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(StartCount);
for i := 0 to pList.Count - 1 do
begin
aTreeNode := TreeView1.Items.Add(nil,pList.VMot[i].iVerb);
TreeView1.Items.AddChild(aTreeNode,pList.VMot[i].eVerb);
QueryPerformanceCounter(StopCount);
TimingSeconds := (StopCount - StartCount) / Freq;
TreeView1.Items.EndUpdate;
TreeView1.Items[0].Selected := true;
StatusBar1.Panels[0].Text := (' ' + inttostr(pList.Count - 1) + ' verbs : ' + FloatToStrF(TimingSeconds, ffGeneral, 3, 2) + ' seconds');
end;
end;
- Code: Select all
procedure TForm4.Button2Click(Sender: TObject);
var
Freq, StartCount, StopCount: Int64;
TimingSeconds: double;
begin
QueryPerformanceFrequency(Freq);
QueryPerformanceCounter(StartCount);
TreeView1.Items.Clear;
QueryPerformanceCounter(StopCount);
TimingSeconds := (StopCount - StartCount) / Freq;
StatusBar1.Panels[1].Text := (' Cleared in... ' + FloatToStrF(TimingSeconds, ffGeneral, 3, 2) + ' seconds');
end;