When should I use VirtualTree's BeginSynch vs BeginUpdate?
Asked Answered
S

1

10

We've started using VirtualTreeView v5.5.3 with Delphi7 since 1 year and love it!

We would like to use the full potential of the component, but there is only a little information about the BeginSynch method in the help file.

When should BeginSynch + EndSynch be used compared to BeginUpdate + EndUpdate?

Which one should be nested into the other?

What methods can be used in which case? (Sort, ScrollIntoView, MoveTo, NodeHeight, isVisible[], ... ) to group manipulations before painting to speed up the app?

Sagamore answered 4/9, 2019 at 4:21 Comment(1)
From docs: Similar to BeginUpdate does BeginSynch provide a mechanism to bring certain events into a common line. That means, whenever you need to make sure change events are called before a modification in the tree is finished (e.g. when changing the focus or selection) then use the synchronous mode started with BeginSynch (and stopped with EndSynch). So, from my understand, BeginSynch = BeginUpdate + some special work with events organization, so simple BeginUpdate should be faster.Evelunn
S
9

To my understanding they have different, almost opposite purposes, and for your use case you would need BeginUpdate.

BeginUpdate is typically called when you want to do a lot of updates, and you don't want redrawing etc to happen during that process. Many controls, including TListBox and TDBGrid, have this possibility to speed up bulk updates.

BeginSynch is related to events, especially the OnChange event. The VirtualTreeView can fire the OnChange event with some delay when you set the ChangeDelay property to a value higher than 0. This also means that you may miss some events. If you make two changes in rapid succession, you may only get one event, or you may get the event later than desired. BeginSynch will start a synchronous mode that fires the OnChange event immediately after (in sync with) the change being made, overriding the ChangeDelay property. Starting this sync mode is easier than saving the value of the ChangeDelay property and restoring it afterwards.

So in a way, you could say that BeginUpdate and BeginSync are almost opposites of each other, in terms of speed, but really it's just about what your usecase is. For your case ("grouping manipulations") you would definitely use BeginUpdate.

The documentation on BeginSynch could be a bit more clear in this regard. It refers to BeginUpdate because it's a similar kind of mechanism (entering some kind of update mode, with a correlating EndSomething method), while actually it should refer to ChangeDelay which it is functionally related to. It's also interesting that the 'Send feedback' link at the bottom of the documentation is not actually a link...

Spatz answered 4/9, 2019 at 10:48 Comment(1)
"BeginSynch will start a synchronous mode that fires the OnChange event immediately after (in sync with) the change being made, overriding the ChangeDelay property." << Perfect answer! Now I understand. Thank you!Sagamore

© 2022 - 2024 — McMap. All rights reserved.