Index: VerpakkingsDefinitie/UI/Util.pas =================================================================== diff -u -r551 -r559 --- VerpakkingsDefinitie/UI/Util.pas (.../Util.pas) (revision 551) +++ VerpakkingsDefinitie/UI/Util.pas (.../Util.pas) (revision 559) @@ -2,15 +2,44 @@ interface -uses System.Types, Vcl.Graphics; // Color lightener +uses + Vcl.Controls, // Free control children + System.Types, Vcl.Graphics; // Color lightener type + TUtilControls = class + class procedure FreeControlChildrenRec(AControl: TControl); + end; + TUtilColorLightener = class - class function LightenColor(RGB: Cardinal; Percentage: Integer): Cardinal;static; + class function LightenColor(RGB: Cardinal; Percentage: Integer): Cardinal; static; end; implementation +// FREE CONTROL CHILDREN +// Recursieve methode om de kinderen van een TWinControl te free-en (hanging pointers voorkomen) +// Gebaseerd op: https://stackoverflow.com/questions/414928/is-there-any-way-to-get-all-the-controls-on-a-container-control +class procedure TUtilControls.FreeControlChildrenRec(AControl: TControl); +var + item: TControl; + i: Integer; +begin + if AControl = nil then + exit; + if AControl is TWinControl then + begin + i := 0; + // Tijden het free-en kan zijn dat er elementen verdwijnen uit de lijst. + // Het aantal elementen moet dus steeds opnieuw gecontroleerd worden (een for-lus berekent dit eenmalig) + while TWinControl(AControl).ControlCount < i do + begin + FreeControlChildrenRec(TWinControl(AControl).Controls[i]); + end; + end; + AControl.Free(); +end; + // COLOR LIGHTENER // https://stackoverflow.com/questions/39569710/how-to-lighten-or-darken-a-specified-tcolor-in-inno-setup-pascal-script function GetRValue(RGB: Cardinal): Byte;