{*******************************************************} { } { Methods of FmxObject } { } { CopyRight (C) 2018-2020 KngStr } { } {*******************************************************} unit ksFmxUtils; interface uses FMX.Types; procedure FreeFmxObject(AFmxObject: TFmxObject); procedure FreeAndNilFmxObject(var AFmxObject); implementation uses ksObjUtils; procedure FreeFmxObject(AFmxObject: TFmxObject); begin if not Assigned(AFmxObject) then Exit; if Assigned(AFmxObject.Owner) then AFmxObject.Owner.RemoveComponent(AFmxObject); if Assigned(AFmxObject.Parent) then begin // fix release error in 10.4, eg: TMemo on TFrame, Windows. AFmxObject.SetRoot(nil); AFmxObject.Parent := nil; end; FreeObject(AFmxObject); end; procedure FreeAndNilFmxObject(var AFmxObject); var ATemp: TFmxObject; begin if Pointer(AFmxObject) = nil then Exit; ATemp := TFmxObject(AFmxObject); Pointer(AFmxObject) := nil; FreeFmxObject(ATemp); end; end.