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