Board index » delphi » OnExit and setting focus question (am I crazy?)

OnExit and setting focus question (am I crazy?)

Can someone please help jog my memory? A few years ago, I was writing a data
entry program. I remember trying to do field validation in a TField.OnExit.
If the field was invalid, I tried to set the focus back to that field. I
remember that this caused Windows to get quite confused, so I opted for
another method.

Well, I tried this again just now, and it works fine. No confusion problem
at all.

Can someone else check me on this? I may be crazy, but it looks like
whatever problem I faced before has been eliminated. I'm wondering if some
version of Delphi corrected this (although I'm sure it was a Windows
problem, not Delphi).

The reason I'm asking is that I've taken over an existing project, and it
does this kind of field validation all through it. I was going to re-design
the field validation, but it seems to work fine. So now I'm wondering if I'm
crazy.

Can anyone out there help figure this out?

-Dan Thomas

 

Re:OnExit and setting focus question (am I crazy?)


Quote
"Dan Thomas" <nob...@nospam.com> wrote in message

news:3a1ac435$1_2@dnews...

Quote
> Can someone please help jog my memory? A few years ago, I was
writing a data
> entry program. I remember trying to do field validation in a
TField.OnExit.
> If the field was invalid, I tried to set the focus back to that
field. I
> remember that this caused Windows to get quite confused, so I opted
for
> another method.

Even though it will work in some cases, it is still best not to change
focus while Windows is in the middle of it. It would be better to use
a message based method of setting the focus back to the control after
Windows finishes.

Woody

Re:OnExit and setting focus question (am I crazy?)


Quote
"Woody" <woody....@ih2000.net> wrote in message news:3a1ad29a$1_2@dnews...
> Even though it will work in some cases, it is still best not to change
> focus while Windows is in the middle of it. It would be better to use
> a message based method of setting the focus back to the control after
> Windows finishes.

Thanks for the response. I have some questions:

"Even though it will work in some cases..." -- under what circumstances will
it not work?

"...it is still best not to change focus while Windows is in the middle of
it" -- Why? Can you give me an example of where this causes problems?

-Dan

Re:OnExit and setting focus question (am I crazy?)


On Tue, 21 Nov 2000 12:22:04 -0800, "Dan Thomas" <nob...@nospam.com>
wrote:

Quote
> under what circumstances will it not work?

You'd have to test under all versions of Windows and with lots of
scenarios to have a complete and authoritative list. Feel free to do
so. In my experience, it more often doesn't work, than work.

Quote
> Can you give me an example of where this causes problems?

For example, showing a dialog in an edit's OnExit event will destroy
the blinking caret.
--
Rick Rogers (TeamB); Fenestra Technologies, http://www.fenestra.com/
  Use Borland servers; posts via others are not seen by TeamB.
  For more info, see http://www.borland.com/newsgroups/genl_faqs.html

Re:OnExit and setting focus question (am I crazy?)


"Rick Rogers (TeamB)" <r...@fenestra.com> wrote in message
news:fnml1to8o21kg0k5qkqncq8d1vihb486ks@4ax.com...

Quote
> For example, showing a dialog in an edit's OnExit event will destroy
> the blinking caret.

That's what I thought also. But in running a simple test under Windows 98,
NT 4, and 2000, it works fine. Are we certain that Borland didn't come up
with a solution to this problem, and we just don't know it's fixed? (I know
this was a Windows-specific problem, not Delphi-specific, but that doesn't
preclude the possibility that Borland developed code to work around it.)

-Dan

Re:OnExit and setting focus question (am I crazy?)


Quote
"Dan Thomas" <nob...@nospam.com> wrote in message

news:3a1add82$1_2@dnews...

Quote
> That's what I thought also. But in running a simple test under
Windows 98,
> NT 4, and 2000, it works fine. Are we certain that Borland didn't
come up
> with a solution to this problem, and we just don't know it's fixed?
(I know
> this was a Windows-specific problem, not Delphi-specific, but that
doesn't
> preclude the possibility that Borland developed code to work around
it.)

As Rick was pointing out, there is no clear way to determine what will
and will not work all the time. Because it is a Windows problem there
is no way to fully compensate for it in Delphi so the answer is, IMO,
that Borland can not provide a "complete" work around for this.

Woody

Re:OnExit and setting focus question (am I crazy?)


Quote
"Woody" <woody....@ih2000.net> wrote in message news:3a1be900_2@dnews...
> As Rick was pointing out, there is no clear way to determine what will
> and will not work all the time. Because it is a Windows problem there
> is no way to fully compensate for it in Delphi so the answer is, IMO,
> that Borland can not provide a "complete" work around for this.

Before I respond, let me say this: I really appreciate the responses. I'm
glad you guys are helping me think this out. So please don't take offense at
anything I'm about to say <grin>.

Let me state 3 things:

1) I completely agree that this is a Windows problem.

2) I've experienced this problem in the past.

3) I can't duplicate the problem now.

Number 3 leads me to these 3 possible conclusions:

A) I was wrong in the past -- the problem never existed.

B) The problem still exists -- I just haven't seen any code to duplicate it.

C) The problem no longer exists, due to some unexplained reason.

We all agree that "A" is not true. We've all seen the problem. You guys
would seem to agree with "B". If this is in fact true, then can someone
please supply me with some code that will cause this problem? I seem to
recall that it was easy to duplicate this problem.

Here's the important point: If nobody can come up with code to duplicate the
problem, then there's a very real possibility that "C" is true, in which
case we don't need to worry about this any more in our code.

Again, let me be as clear as possible: If nobody can come up with code to
duplicate this problem, then perhaps it doesn't exist any more!

So can someone please show some code that causes the problem?

-Dan

Re:OnExit and setting focus question (am I crazy?)


Quote
In article <3a1ac435$1_2@dnews>, Dan Thomas wrote:
> The reason I'm asking is that I've taken over an existing project, and it
> does this kind of field validation all through it. I was going to re-design
> the field validation, but it seems to work fine. So now I'm wondering if I'm
> crazy.

> Can anyone out there help figure this out?

Try issuing a ShowMessage in your OnExit - that should mess up the caret
display.

 Mike Orriss (TeamB & Developer Express)
 (Unless stated otherwise, my replies relate to Delphi 5)
 (No unsolicited e-mail replies please)

Re:OnExit and setting focus question (am I crazy?)


"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.00001f42.0ccc88ea@mikemain...

Quote
> Try issuing a ShowMessage in your OnExit - that should mess up the caret
> display.

That's exactly what I tried, and it didn't mess anything up. Does it mess up
the caret when you try it?

-Dan

Re:OnExit and setting focus question (am I crazy?)


Quote
In article <3a1c2bc2$1_1@dnews>, Dan Thomas wrote:
> That's exactly what I tried, and it didn't mess anything up. Does it mess up
> the caret when you try it?

OK, you persuaded me to make the effort <g>
No, it appears to work fine now.

 Mike Orriss (TeamB & Developer Express)
 (Unless stated otherwise, my replies relate to Delphi 5)
 (No unsolicited e-mail replies please)

Re:OnExit and setting focus question (am I crazy?)


Because I am still using D2, I can't put together anything that would
be useful for you. I always look at it this way, though, if I know
there is a potential problem on some machines and/or configurations, I
try to avoid situations that tend to favor those problems. Even though
there may be areas that have improved with the focusing of components,
IMHO, it is still probably better to do things in a manner consistent
with safety.

my $0.02

Woody

Re:OnExit and setting focus question (am I crazy?)


Quote
"Woody" <woody....@ih2000.net> wrote in message news:3a1d5280_2@dnews...
> Because I am still using D2, I can't put together anything that would
> be useful for you. I always look at it this way, though, if I know
> there is a potential problem on some machines and/or configurations, I
> try to avoid situations that tend to favor those problems. Even though
> there may be areas that have improved with the focusing of components,
> IMHO, it is still probably better to do things in a manner consistent
> with safety.

I would agree with you most of the time -- in fact, the vast majority of
time. But in this case I disagree, because working around this can become so
convoluted.

Since you have D2, can you do me a favor? Put 2 TEdit controls on a form,
and do a ShowMessage in the OnExit of one of them, and see what happens. I
think this will cause problems in D2. Thanks.

-Dan

Re:OnExit and setting focus question (am I crazy?)


"Mike Orriss (TeamB)" <m...@3kcc.co.uk> wrote in message
news:VA.00001f43.006935ce@mikemain...

Quote
> In article <3a1c2bc2$1_1@dnews>, Dan Thomas wrote:
> > That's exactly what I tried, and it didn't mess anything up. Does it
mess up
> > the caret when you try it?

> OK, you persuaded me to make the effort <g>

> No, it appears to work fine now.

Thanks for checking it out. Now I know I'm not crazy <grin>.

-Dan

Re:OnExit and setting focus question (am I crazy?)


Quote
"Dan Thomas" <nob...@nospam.com> wrote in message

news:3a2292e6$1_2@dnews...

Quote
> I would agree with you most of the time -- in fact, the vast
majority of
> time. But in this case I disagree, because working around this can
become so
> convoluted.

> Since you have D2, can you do me a favor? Put 2 TEdit controls on a
form,
> and do a ShowMessage in the OnExit of one of them, and see what
happens. I
> think this will cause problems in D2. Thanks.

I don't even have to do it to know it will because I've run into the
problem before.

Woody

Re:OnExit and setting focus question (am I crazy?)


Quote
"Woody" <woody....@ih2000.net> wrote in message news:3a22cd43$1_1@dnews...
> "Dan Thomas" <nob...@nospam.com> wrote in message
> news:3a2292e6$1_2@dnews...
> > I would agree with you most of the time -- in fact, the vast
> majority of
> > time. But in this case I disagree, because working around this can
> become so
> > convoluted.

> > Since you have D2, can you do me a favor? Put 2 TEdit controls on a
> form,
> > and do a ShowMessage in the OnExit of one of them, and see what
> happens. I
> > think this will cause problems in D2. Thanks.

> I don't even have to do it to know it will because I've run into the
> problem before.

OK, then I think we've probably proven that this is no longer a problem.
Thanks for your help.

-Dan

Other Threads