I have several TPanels that are populated with buttons at runtime. However the code below that i use to free my buttons from their parent panels sometimes generates access violation errors.
procedure TfrmTakeOrder.FreeItemButtons(buttons : array of TButton);
var
cnt,i : integer;
begin
for i := 0 to gridLayoutItems.ControlCount - 1 do
begin
buttons[i].Free;
buttons[i] := nil;
end;
end;
Is there a better way to do this?Please keep in mind that other Panels have buttons too and I would like to have a "localised" freeing of the buttons that wount intefer with other panels.
It looks to me like you are trying to remove all buttons from a TPanel and that panel only contains buttons.
Try this:
while gridLayoutItems.ControlCount > 0 do
gridLayoutItems.Controls[0].Free;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With