This site is moving to The Zen Source Library
Please Update your bookmarks


BeginUpdate..EndUpdate


When adding more than 1 Node to a TTreeView its wise to call BeginUpdate and EndUpdate. BeginUpdate stops all TreeView redraws while nodes are being added to the TreeView. EndUpdate displayes all the updates that were made.

It is suprising how much you can speed up your applications by using BeginUpdate..EndUpdate. Its so easy to do, it be great if all optimizations were this easy!


   var
      iLoop : integer;
      sStart : string;
   begin
         {Word with an empty tree}
      TreeView.Items.Clear;

         {Start time}
      sStart := FormatDateTime(  'hh:nn:ss',  now  );

         {Prepare for update}
      TreeView.Items.BeginUpdate;

         {Add 1000 root items}
      for iLoop := 0 to 1000 do
         TreeView.Items.AddFirst(  nil,  IntToStr(  iLoop  )  );

         {Finished update}
      TreeView.Items.EndUpdate;


         {Show start + end times}
      ShowMessage(   sStart + #13#10 +
                     FormatDateTime(  'hh:nn:ss',  now  )
                  );
   end;


Try the above code with and without the BeginUpdate..EndUpdate calls. On my machine the results were quite astounding! With BeginUpdate..EndUpdate the function executed in less than 1 second. Without the BeginUpdate..EndUpdate calls it took about 30 seconds!

One last thing the Win32 help says Tree nodes affected by the changes will have invalid Index values until EndUpdate is called. So dont use Node Indexes while in a BeginUpdate..EndUpdate "Block".






All information on these www pages is copyright (©) 1997 Andre .v.d. Merwe And may not be copied or mirrored without my permission.