Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Marder committed Jan 18, 2016
2 parents 5097734 + f6f0a2e commit bebe2ab
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Source/VirtualTrees.pas
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ TVTReference = record
function GetData(): Pointer; overload; inline;
function GetData<T>(): T; overload; inline;
procedure SetData(pUserData: Pointer); overload;
procedure SetData<T:class>(pUserData: T); overload;
procedure SetData<T>(pUserData: T); overload;
procedure SetData(const pUserData: IInterface); overload;
end;

Expand Down Expand Up @@ -3028,7 +3028,7 @@ TBaseVirtualTree = class(TCustomControl)
procedure SetCheckStateForAll(aCheckState: TCheckState; pSelectedOnly: Boolean);
procedure SetNodeData(pNode: PVirtualNode; pUserData: Pointer); overload; inline;
procedure SetNodeData(pNode: PVirtualNode; const pUserData: IInterface); overload; inline;
procedure SetNodeData<T:class>(pNode: PVirtualNode; pUserData: T); overload;
procedure SetNodeData<T>(pNode: PVirtualNode; pUserData: T); overload;
procedure Sort(Node: PVirtualNode; Column: TColumnIndex; Direction: TSortDirection; DoInit: Boolean = True); virtual;
procedure SortTree(Column: TColumnIndex; Direction: TSortDirection; DoInit: Boolean = True); virtual;
procedure ToggleNode(Node: PVirtualNode);
Expand Down Expand Up @@ -14779,7 +14779,7 @@ procedure TBaseVirtualTree.SetFiltered(Node: PVirtualNode; Value: Boolean);
Include(Node.States, vsFiltered);
if not (toShowFilteredNodes in FOptions.FPaintOptions) then
begin
if vsInitializing in Node.States then
if (vsInitializing in Node.States) and not (vsHasChildren in Node.States) then
AdjustTotalHeight(Node, 0, False)
else
AdjustTotalHeight(Node, -Integer(NodeHeight[Node]), True);
Expand Down Expand Up @@ -14958,7 +14958,7 @@ procedure TBaseVirtualTree.SetNodeData<T>(pNode: PVirtualNode; pUserData: T);
// Can be used to set user data of a PVirtualNode to a class instance.

begin
SetNodeData(pNode, Pointer(pUserData));
pNode.SetData<T>(pUserData);
end;

procedure TBaseVirtualTree.SetNodeData(pNode: PVirtualNode; const pUserData: IInterface);
Expand Down Expand Up @@ -19889,6 +19889,8 @@ procedure TBaseVirtualTree.DoFocusNode(Node: PVirtualNode; Ask: Boolean);

procedure TBaseVirtualTree.DoFreeNode(Node: PVirtualNode);

var
IntfData: IInterface;
begin
// Prevent invalid references
if Node = FLastChangedNode then
Expand All @@ -19908,7 +19910,12 @@ procedure TBaseVirtualTree.DoFreeNode(Node: PVirtualNode);
FOnFreeNode(Self, Node);

if vsReleaseCallOnUserDataRequired in Node.States then
GetInterfaceFromNodeData<IInterface>(Node)._Release();
begin
// Data may have been set to nil, in which case we can't call _Release on it
IntfData := GetInterfaceFromNodeData<IInterface>(Node);
if Assigned(IntfData) then
IntfData._Release();
end;

FreeMem(Node);
if Self.UpdateCount = 0 then
Expand Down Expand Up @@ -34478,7 +34485,13 @@ procedure TVirtualNode.SetData(const pUserData: IInterface);
procedure TVirtualNode.SetData<T>(pUserData: T);

begin
SetData(Pointer(pUserData));
T(Pointer((PByte(@(Self.Data))))^) := pUserData;
case PTypeInfo(TypeInfo(T)).Kind of
tkClass:
Include(Self.States, vsOnFreeNodeCallRequired);
tkInterface:
Include(Self.States, vsReleaseCallOnUserDataRequired);
end;
end;

{ TVTImageInfo }
Expand Down

0 comments on commit bebe2ab

Please sign in to comment.