Thank you
engkin.
I can destroy the component (myGrid) in one Buttons.OnClick-Event and the applications closes without exception.
I commented out this code in LCL:
destructor TWinControl.Destroy;
...
//COMENT OUT: if Parent <> nil then
//COUMMENT OUT: RemoveFocus(true);
it doesnt' helped.
I modified in LCL:
procedure TWinControl.RemoveFocus(Removing : Boolean);
var
Form: TCustomForm;
begin
Form := GetParentForm(Self);
//ORIGINAL: if Form <> nil then Form.DefocusControl(Self, Removing);
//CHANGED TO:
if (Form <> nil)and not (csDestroying in Form.ComponentState) then
Form.DefocusControl(Self, Removing); //soner added
end;
Also, it doesnt' helped.
This error happens only if i start application from Lazarus IDE and destroy the Grid in forms OnDestroy event.
I runned this example in Delphi 7 without error.
I think this is a design error of LCL or IDE/Debugger. Maybe located in TComponent's remove-components functions. Because I have the same error, when I create and destroy TDataModule manually. And TDataModule has no focus.
Now first I let them destroy automatic. Maybe one day i can locate the error in LCL.