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

cannot focus a disabled or invisible window

955 views
Skip to first unread message

Jeremy Pemberton

unread,
Jun 1, 2003, 7:08:14 PM6/1/03
to

I've gone around in circles with this one for a couple hours or so and I truly believe I am getting this error for no reason at all!
There seems to be something wrong with the TCheckBox object (its never the programmer you know ;-).

Below is the hierarchy:
Form1 (TForm)
--- Pages1 (TPageControl)
------ (TabSheet2)
--------- Panel2 (TPanel)
------------ BitBtn4 (TBitBtn)
--------- Panel3 (TPanel)
------------ Checkbox2 (TCheckBox)

The error comes up when I try to change Checkbox2's checked property. The code is as below and is called from BitBtn4.OnClick in the other Panel. I initially thought the problem was caused by executing the code from a different container (Panel2 instead of Panel3 where the checkbox lies), however I explicitly entered code to switch the focus before changing the checked property, to no avail however. Also put code in to make sure the checkbox is enabled and visible, still the error comes up.
What else can it be? Your help is much appreciated!

If Pages1.ActivePageIndex = 1 then
begin
Panel3.SetFocus;
With CheckBox2 do
begin
Enabled := true;
Visible := true;
SetFocus;
Checked := False;
end;
Panel2.SetFocus;
end;


Jeremy

Andrew Muir

unread,
Jun 1, 2003, 11:15:53 PM6/1/03
to
Do you have any code in the checkbox onclick event ?

"Jeremy Pemberton" <ple...@zerospam.hot-mail.com> wrote in message
news:3eda875e$1...@newsgroups.borland.com...

Sujit Singhania

unread,
Jun 2, 2003, 7:22:13 AM6/2/03
to
Jeremy Pemberton <ple...@zerospam.hot-mail.com> wrote in message
news:3eda875e$1...@newsgroups.borland.com...
>
> I've gone around in circles with this one for a couple hours or so and I
truly believe I am getting this error for no reason at all!
> There seems to be something wrong with the TCheckBox object (its never
the programmer you know ;-).
>

<snip>

> If Pages1.ActivePageIndex = 1 then
> begin
> Panel3.SetFocus;

Use:
Pages1.ActivePage:=Panel3;

> With CheckBox2 do
> begin
> Enabled := true;
> Visible := true;
> SetFocus;

No need for the above three lines if Checkbox2 is always enabled and
visible.

> Checked := False;
> end;
> Panel2.SetFocus;
> end;
>

In D3, the above code used to work for me. Don't know about the higher
versions though.

Sujit

Jeremy Pemberton

unread,
Jun 3, 2003, 12:11:35 AM6/3/03
to

An eye-opener indeed Andrew, thanks for the hint. Didn't even think of that before. The checkbox does have an OnClick event as follows;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
LabeledEdit11.Enabled := CheckBox2.Checked;
CB_SheetArea1.Enabled := CheckBox2.Checked;
StringGrid2.Enabled := CheckBox2.Checked;
// move ctrl to price (required field)
LabeledEdit11.SetFocus;
end; {Calculate costs checkbox}

The last tine (LabeledEdit11.SetFocus;) is the one that causes the exception as the object is in the other panel. I fixed the problem by changing that line to read;

If CheckBox2.Checked then LabeledEdit11.SetFocus;

Thanks again for the eye-opener, had forgotten about the OnClick completely.
Sujit: I tried the (Pages1.ActivePage:=Panel3;) but it doesn't work in D7 as ActivePage is of type TTabSheet and hence won't take a TPanel object. Thanks for the suggestion anyhow.

Jeremy

Chris Luck

unread,
Jun 3, 2003, 1:23:41 AM6/3/03
to
"Jeremy Pemberton" <ple...@zerospam.hot-mail.com> wrote in message
news:3edc1ff7$1...@newsgroups.borland.com...

>
> The last tine (LabeledEdit11.SetFocus;) is the one that causes the
exception as the object is in the other panel. I fixed the problem by
changing that line to read;
>
> If CheckBox2.Checked then LabeledEdit11.SetFocus;


Much safer to adopt the practice of setting ActiveControl rather than
specifically setting the focus. When ActiveControl is set the TWinControl
will take the focus if it can, if it cannot then it causes no distress. You
can even set the ActiveControl on a hidden form.

--
Regards,
Chris Luck.

0 new messages