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

CanFocus and SetFocus

171 views
Skip to first unread message

Nick Pollard

unread,
Sep 6, 2002, 7:39:50 AM9/6/02
to
Hi,

I have the following code:

if Self.CanFocus then
Self.SetFocus;

This results in an exception saying 'You cannot focus an invisible or
disabled window'. I thought that the point in CanFocus was to check this.
Am I doing something wrong?

In this case Self is a TFrame descendant. A colleague of mine has also
experienced a similar problem with TTreeView.

Regards,

Nick Pollard


Nick Pollard

unread,
Sep 6, 2002, 7:53:34 AM9/6/02
to
I think this is caused because this code is fired from the FormCreate event
of the form that is the ultimate parent of the frame and is not yet visible
(even though CanFocus is true).


"Nick Pollard" <nr...@hotmail.com> wrote in message
news:3d7885f6$1...@newsgroups.borland.com...

Chris Luck

unread,
Sep 6, 2002, 7:57:33 AM9/6/02
to
"Nick Pollard" <nr...@hotmail.com> wrote in message
news:3d78892e$1...@newsgroups.borland.com...

> I think this is caused because this code is fired from the FormCreate
event
> of the form that is the ultimate parent of the frame and is not yet
visible
> (even though CanFocus is true).

It is often safer to set ActiveControl rather than directly set the focus.
When the active control is able to receive focus it will do so.


--
Regards,
Chris Luck.


0 new messages