Skip to content

Commit 0793fe4

Browse files
committed
Introduced function IsUpdating which can be used instead of checking for flag tsUpdating or (fUpdateCount > 0). Issue #1013.
1 parent 717e6ea commit 0793fe4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Source/VirtualTrees.pas

+12-5
Original file line numberDiff line numberDiff line change
@@ -3130,6 +3130,7 @@ TBaseVirtualTree = class(TCustomControl)
31303130
function IsEditing: Boolean;
31313131
function IsMouseSelecting: Boolean;
31323132
function IsEmpty: Boolean; inline;
3133+
function IsUpdating(): Boolean;
31333134
function IterateSubtree(Node: PVirtualNode; Callback: TVTGetNodeProc; Data: Pointer; Filter: TVirtualNodeStates = [];
31343135
DoInit: Boolean = False; ChildNodesOnly: Boolean = False): PVirtualNode;
31353136
procedure LoadFromFile(const FileName: TFileName); virtual;
@@ -8431,7 +8432,7 @@ procedure TVirtualTreeColumns.Update(Item: TCollectionItem);
84318432
Treeview.Invalidate;
84328433
end;
84338434

8434-
if not (tsUpdating in Treeview.FStates) then
8435+
if not (Treeview.IsUpdating) then
84358436
// This is mainly to let the designer know when a change occurs at design time which
84368437
// doesn't involve the object inspector (like column resizing with the mouse).
84378438
// This does NOT include design time code as the communication is done via an interface.
@@ -19727,7 +19728,7 @@ procedure TBaseVirtualTree.DoColumnResize(Column: TColumnIndex);
1972719728
if [hsColumnWidthTracking, hsResizing] * FHeader.States = [hsColumnWidthTracking] then
1972819729
UpdateWindow(Handle);
1972919730

19730-
if not (tsUpdating in FStates) then
19731+
if not (IsUpdating) then
1973119732
UpdateDesigner; // design time only
1973219733

1973319734
if Assigned(FOnColumnResize) and not (hsResizing in FHeader.States) then
@@ -23280,7 +23281,7 @@ procedure TBaseVirtualTree.InternalClearSelection();
2328023281
// It is possible that there are invalid node references in the selection array
2328123282
// if the tree update is locked and changes in the structure were made.
2328223283
// Handle this potentially dangerous situation by packing the selection array explicitely.
23283-
if FUpdateCount > 0 then
23284+
if IsUpdating then
2328423285
begin
2328523286
Count := PackArray(FSelection, FSelectionCount);
2328623287
if Count > -1 then
@@ -30019,6 +30020,12 @@ function TBaseVirtualTree.IsMouseSelecting: Boolean;
3001930020
Result := (tsDrawSelPending in FStates) or (tsDrawSelecting in FStates);
3002030021
end;
3002130022

30023+
function TBaseVirtualTree.IsUpdating: Boolean;
30024+
// The tree does currently not update its window because a BeginUpdate has not yet ended.
30025+
begin
30026+
Exit(UpdateCount > 0);
30027+
end;
30028+
3002230029
//----------------------------------------------------------------------------------------------------------------------
3002330030

3002430031
function TBaseVirtualTree.IterateSubtree(Node: PVirtualNode; Callback: TVTGetNodeProc; Data: Pointer;
@@ -32636,7 +32643,7 @@ procedure TBaseVirtualTree.UpdateHorizontalScrollBar(DoRepaint: Boolean);
3263632643
begin
3263732644
UpdateHorizontalRange;
3263832645

32639-
if (FUpdateCount > 0) or not HandleAllocated then
32646+
if IsUpdating or not HandleAllocated then
3264032647
Exit;
3264132648

3264232649
// Adjust effect scroll offset depending on bidi mode.
@@ -32743,7 +32750,7 @@ procedure TBaseVirtualTree.UpdateVerticalScrollBar(DoRepaint: Boolean);
3274332750
begin
3274432751
UpdateVerticalRange;
3274532752

32746-
if (fUpdateCount > 0) then
32753+
if (IsUpdating) then
3274732754
Exit;
3274832755
Assert(GetCurrentThreadId = MainThreadId, 'UI controls like ' + Classname + ' and its scrollbars should only be manipulated through the main thread.');
3274932756

0 commit comments

Comments
 (0)