Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cannot focus a disabled or invisible window.

16 views
Skip to first unread message

Craig T Hunt

unread,
May 27, 2000, 3:00:00 AM5/27/00
to
Environment: Windows 98, Delphi 5.0 Update Pack 1, InfoPower 2000.10, and
DBISAM 1.21

In a Modal application I have a form that is giving me fits! The form
consists of a PageControl and four TabSheets. The first time the form is
displayed (ShowModal) it displays as expected. If the form is closed (no
changes made to anything on the form and only the Active TabSheet displayed)
and I attempt to display the form again, I get "Cannot focus a disabled or
invisible window." To show the form again, I have to quit and restart the
application.

If I remove all the coded procedures in the form (except for its Close
statement), the form redisplays as expected.

Even if there is errant code in the form, I'm thinking that Free should
destroy everything associated with the form when it is closed and the next
ShowModal would create an entirely new form without any underlying problems.
Am I correct or incorrect in my assumption? What could be causing this
problem or what should I be looking for?

The menu form that displays the problem form shows twelve other forms
without any problem. However, the form in question is the only PageControl
form. Does this make a difference?

The problem form is being shown by the following procedure.

procedure TformSetupMenu1.btnCompanyPreferencesSetupClick(Sender: TObject);
begin
with TformSetupCompanyPreference.Create(nil) do
try
ShowModal;
finally
Free;
end;
end;


Thanks for any and all assistance.

Have an enjoyable Memorial Day weekend...

Craig Hunt


Richard Davis

unread,
May 28, 2000, 3:00:00 AM5/28/00
to
In the form TformSetupCompanyPreference, does the FormCreate method
try to set focus to a control? Or any other method that fires before
the ShowModal is called? If so, you'll get that error since the form
isn't 'showing' yet so the form, and therefore the control, is
invisible. Possibly something that only gets set the second time in
during a session.

Rich

Brandon C. Smith

unread,
May 28, 2000, 3:00:00 AM5/28/00
to
I don't know if it'll work for you, but in a similar situation, I simply set
Myform.visible := false in the line before I called showmodal the second
(and potentially multiple more) time(s).

Brandon Smith

Craig T Hunt

unread,
May 30, 2000, 3:00:00 AM5/30/00
to
Sorry for not getting back to you earlier.

My mind was all messed up there for awhile... The culprit ended up being a
RadioGroup's OnChange event that fires before the form's OnShow event.
Adding a number of MessageDlg to the form in question allowed me to
determine what procedures were firing and when. In the future, I think I'll
think twice before using a RadioGroup's OnChange event again.

I have a DBRadioGroup on one of the TabSheets on the form's PageControl.
Some of that TabSheet's controls are disabled depending upon what Item is
chosen in the RadioGroup. I use the RadioGroup's OnChange event to tell me
which Item was clicked. I couldn't use the OnClick event since that event
tells you which item was selected *prior* to the item clicked.

When the form is created:
(1) the RadioGroup's OnChange event is triggered.

When the form is displayed (ShowModal):
(2) the first (active) TabSheet's OnShow event is triggered
(3) the form's OnShow event is triggered
(4) the PageControl's Enter event is triggered

The timing of these events is not what I would have expected. In my mind I
would have thought the events would have fired off in the following order.
(3), (4) and (2). I never thought that (1) would have fired.

The second time the form is created:
(1) the RadioGroup's OnChange event is triggered.
This is when I received the "Cannot focus a disabled or invisible window."
message.

I had to add a variable and some logic to the form to *not* do the OnChange
logic if the form's OnShow event wasn't executed before the OnChange event.

e.g.,

procedure TformSetupCompanyPreference.FormShow(Sender: TObject);
begin
...
...
ws_FormActive := True;
end;
{ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> }

procedure TformSetupCompanyPreference.RgPeriodBillingOptionsChange(Sender:
TObject);
begin
if ws_FormActive = True then
begin
DoRgPeriodBillingOptionsChangeNow;
end;
end;
{ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> }

procedure TformSetupCompanyPreference.DoRgPeriodBillingOptionsChangeNow;
begin
if rgPeriodBillingOptions.value = wc_NoPeriodBilling then
begin
DisableNoTaxComponents;
dbeDayBuffer.Enabled := False;
btnExitProcess.SetFocus;
end;
if rgPeriodBillingOptions.value = wc_DayBillingMode then
begin
EnableNoTaxComponents;
dbeDayBuffer.Enabled := False;
dbcbTax1Exclude.SetFocus;
end;
if rgPeriodBillingOptions.value = wc_MonthBillingMode then
begin
EnableNoTaxComponents;
dbeDayBuffer.Enabled := True;
dbeDayBuffer.SetFocus;
end;
end;
{ <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> }

Thanks,

Craig Hunt


Richard Davis <richar...@nospambigfoot.com> wrote in message
news:39308b3b.3106204@forums.borland.com...


> In the form TformSetupCompanyPreference, does the FormCreate method
> try to set focus to a control? Or any other method that fires before
> the ShowModal is called? If so, you'll get that error since the form
> isn't 'showing' yet so the form, and therefore the control, is
> invisible. Possibly something that only gets set the second time in
> during a session.
>
> Rich
>

0 new messages