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

Disabling the exception "Cannot focus an invisible or hidden control"

3 views
Skip to first unread message

JJ

unread,
May 30, 2008, 1:54:28 PM5/30/08
to
There are times when my users get the exception "Cannot focus an invisible
or hidden control"

I realize that this is a bug in my program, and I fix things like that when
I find them. But there are times when it results in a lot of extra code just
to avoid this exception.
So I'd like to disable the appearance of this exception, so my users never
see it.

Is there a way to do that?


Peter Below (TeamB)

unread,
May 31, 2008, 4:55:38 AM5/31/08
to
JJ wrote:

Bad idea. Problems should be fixed, not hidden.

> Is there a way to do that?

You can use the Application.OnException event. It gets all the
exceptions trapped in the VCL and you can decide there to show the
exception or not.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

JJ

unread,
Jun 2, 2008, 8:00:08 PM6/2/08
to
>> You can use the Application.OnException event. It gets all the
exceptions trapped in the VCL and you can decide there to show the
exception or not.

Thanks!

"Peter Below (TeamB)" <no...@nomail.please> wrote in message
news:xn0fqu13...@newsgroups.borland.com...

Ronald Hoek

unread,
Jun 18, 2008, 7:56:26 AM6/18/08
to
Why not make a routine to modify alle Control.SetFocus to sometinh like
MysetFocus(Control).....

Implement the modified focus code in that routine....

Ex,

function MySetFocus(aWinControl: TWinControl): boolean;

function ParentsEnabled(const aParent: Twincontrol): boolean;
begin
Result := not Assigned(aParent);
if not Result then
Result := aParent.Enabled and aParent.Visible and
ParentsEnabled(aParent.Parent);
end;

begin
Result := Assigned(aWinControl) and aWinControl.Enabled and
aWinControl.Visible and
ParentsEnabled(aWinControl.Parent) and aWinControl.CanFocus;
if Result then
begin
aWinControl.SetFocus;
Result := aWinControl.Focused;
end;
end;


This code dows not fully catch the problem... Then main drawback is when
using dynamic control which are not place on a Form as to level parent....


Ex.
TForm (does nog have a parent!)
TPanel
TButton
TEdit

This wil do ok

TForm (does nog have a parent!)
TPanel
TButton

TEdit (does nog have a parent!)

This we result in a error

--
Regards,

Ronald Hoek

Applicationdevelopper
ComponentAgro B.V.

Martin James

unread,
Jun 19, 2008, 3:22:15 AM6/19/08
to
Yeah - that's cleaner. In my apps, I have just try/excepted round every
SetFocus call <g>

Its's not pretty, but it got rid of the errors.

Rgds,
Martin


0 new messages