diff --git a/lcl/include/control.inc b/lcl/include/control.inc index fb4e355c46..c0e7b654af 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -165,9 +165,16 @@ end; procedure TLazAccessibleObject.RemoveChildAccessibleObject( AObject: TLazAccessibleObject); +var + lIndex: Integer; begin if FChildren = nil then Exit; - FChildren.Remove(@AObject); + lIndex := FChildren.IndexOf(AObject); + if lIndex >= 0 then + begin + TLazAccessibleObject(FChildren.Items[lIndex]).Free; + FChildren.Delete(lIndex); + end; end; function TLazAccessibleObject.GetChildAccessibleObject(AIndex: Integer): TLazAccessibleObject; diff --git a/lcl/include/treeview.inc b/lcl/include/treeview.inc index 18e38c4f36..48cfde2435 100644 --- a/lcl/include/treeview.inc +++ b/lcl/include/treeview.inc @@ -305,6 +305,8 @@ begin end; destructor TTreeNode.Destroy; +var + lOwnerAccessibleObject, lAccessibleObject: TLazAccessibleObject; begin {$IFDEF TREEVIEW_DEBUG} DebugLn('[TTreeNode.Destroy] Self=',DbgS(Self),' Self.Text=',Text); @@ -316,6 +318,15 @@ begin if Assigned(Owner) and Assigned(Owner.Owner) then Owner.Owner.Delete(Self); + // Remove the accessibility object too + if Assigned(Owner) and Assigned(Owner.Owner) then + begin + lOwnerAccessibleObject := Owner.Owner.GetAccessibleObject(); + lAccessibleObject := lOwnerAccessibleObject.GetChildAccessibleObjectWithDataObject(Self); + if lAccessibleObject <> nil then + lOwnerAccessibleObject.RemoveChildAccessibleObject(lAccessibleObject); + end; + // delete children HasChildren := false; // unbind all references