can not focus a disabled or invisible window
can not focus a disabled or invisible window
Hi
I have a required filed in my table and when I dont type any thing in that filed and try to post I get this error "can not focus a disabled or invisible window" instead of exception dialog for null value for required filed
when I unchecked the required fields property the normal exception appear again !! why is that ?
thanks
I have a required filed in my table and when I dont type any thing in that filed and try to post I get this error "can not focus a disabled or invisible window" instead of exception dialog for null value for required filed
when I unchecked the required fields property the normal exception appear again !! why is that ?
thanks
Hello,
The "Cannot focus a disabled or invisible window" exception is raised first, that's why you don't see the exception about NULL value. The "Cannot focus a disabled or invisible window" exception is raised in the TCustomForm.SetActiveControl procedure of the Forms unit. It occurs when your application is trying to make an invisible or disabled control active (for example, by calling the SetFocus method). Please check where your application does this, and you will find the cause of this problem.
The "Cannot focus a disabled or invisible window" exception is raised first, that's why you don't see the exception about NULL value. The "Cannot focus a disabled or invisible window" exception is raised in the TCustomForm.SetActiveControl procedure of the Forms unit. It occurs when your application is trying to make an invisible or disabled control active (for example, by calling the SetFocus method). Please check where your application does this, and you will find the cause of this problem.
I cannot reproduce the problem. Please try creating a small sample to demonstrate this problem and send it to andreyz*devart*com, including a script to create and fill a table. Also please specify the following:
- the exact version of your IDE;
- the exact version of IBDAC. You can learn it from the About sheet of TIBCConnection Editor.
- the exact version of your IDE;
- the exact version of IBDAC. You can learn it from the About sheet of TIBCConnection Editor.
You can pinpoint the problem in the following way:
- enable the "Use Debug DCUs" option in Project-Options;
- set a breakpoint in the Forms unit on the following line: raise EInvalidOperation.Create(SCannotFocus);
This way you can find the reason of the "Cannot focus a disabled or invisible window" error.
- enable the "Use Debug DCUs" option in Project-Options;
- set a breakpoint in the Forms unit on the following line: raise EInvalidOperation.Create(SCannotFocus);
This way you can find the reason of the "Cannot focus a disabled or invisible window" error.
Thanks alot for your advise. I did not face any kind of weird problem like that before
I did the steps you mentioned and I found two raise exceptions in the forms unit I break on both
when I got the error I saw in call stack that the error begin after calling the "post" method and as I said this because I was trying to save a new added record with a "not null" field set to null ! so the software was trying to popup the required exception message
then I looked at the code that launch the form which I set the border to bsdialog:
then I try that:
I comment all the above code until line myfrm.ShowModal and comment the check for mrok and I put the call to post method in the form save button and the call to cancel method in the form cancel button
when I run I got the normal required exception dialog without getting "can not focus a disabled or invisible window" !!
any explanation why that happen ??
I did the steps you mentioned and I found two raise exceptions in the forms unit I break on both
when I got the error I saw in call stack that the error begin after calling the "post" method and as I said this because I was trying to save a new added record with a "not null" field set to null ! so the software was trying to popup the required exception message
then I looked at the code that launch the form which I set the border to bsdialog:
Code: Select all
with myDM do begin
table1.Append;
myfrm := Tmyfrm.Create(self);
if myfrm.ShowModal = mrOk then begin
if table1.State in dseditmodes then
table1.Post;
if table2.State in dseditmodes then
table2.Post;
table1.Refresh;
end
else table1.Cancel;
end;
I comment all the above code until line myfrm.ShowModal and comment the check for mrok and I put the call to post method in the form save button and the call to cancel method in the form cancel button
when I run I got the normal required exception dialog without getting "can not focus a disabled or invisible window" !!
any explanation why that happen ??
I've reproduced the problem. This problem is caused by the TDataSet.CheckRequiredFields method in the DB unit. This method calls the FocusControl method that eventually causes the "Cannot focus a disabled or invisible window" error. The approach you are using is incorrect, it can cause different unexpected problems. You should move your code that works with table1 to the Tmyfrm form. Here is an example:
Code: Select all
with myDM do begin
table1.Append;
myfrm := Tmyfrm.Create(self);
myfrm.ShowModal;
end;
procedure Tmyfrm.btnSaveClick(Sender: TObject);
begin
if myDM.table1.State in dseditmodes then
myDM.table1.Post;
if myDM.table2.State in dseditmodes then
myDM.table2.Post;
myDM.table1.Refresh;
ModalResult := mrOK;
end;
procedure Tmyfrm.btnCancelClick(Sender: TObject);
begin
myDM.table1.Cancel;
ModalResult := mrCancel;
end;
Thanks alot AndreyZ You are wonderful man
I understand now thanks to you but I remember since Delphi 2.0 many examples use ShowModal = mrok with post method !!
howeer your code in previous post is exactly what I use now except I dont check for mrok any more no point since I put he logic in the form save and cancel buttons.
Thanks again I appreciate your help[/code]
I understand now thanks to you but I remember since Delphi 2.0 many examples use ShowModal = mrok with post method !!
howeer your code in previous post is exactly what I use now except I dont check for mrok any more no point since I put he logic in the form save and cancel buttons.
Thanks again I appreciate your help[/code]