On 10/3/06, Charles Yeomans <[EMAIL PROTECTED]> wrote:
> One of the quirks in REALbasic that you must be aware of is that
> the order of events is not guaranteed to be consistent between
> platforms or even different Rb versions. For this reason, putting a
> setfocus in a control losing its focus isn't guaranteed to work.
> The LostFocus event should really be considered as a way to change
> previous property settings in a housekeeping type manner as opposed
> to triggering an event in another object. Setting the focus of
> another object on a keypress should normally be handled within the
> Keydown event of the object if that's what is triggering the focus
> change.

I wouldn't call this a quirk so much as a lack of understanding of
event-driven program design, the REALbasic event construct, and the
fact that the use of the word "event" in both leads people to think
that they are more related than they are.

IMHO, in this case it is not an issue with unconsistent events -
rathar an improper implementation of event dispatching by RB. When
MsgBox is displayed, the window with EditField  gets Deeactivate -
Activate events - which is OK. The window porpagete the events to
EditField as LostFocus - GotFocus, which is imho wrong. As a result,
the EditField got two Lostfocus events followed by GotFocus and the
focus does not move.

The problems with LostFocus firing twice can be easily solved - for
example use a Boolean window property, set it in GotFocus and clear it
in LostFocus. If LostFocus was called and property is not set, ignore
it.

There really is not be any reason why SetFocus should not be called in
LostFocus event. Focus is just a property of Window. In this case, it
seems setting of focus works if set when Lostfocus is called second
time, but not in other cases.

It menas the workaround should be something like

Sub GotFocus()
   haveFocus=True
End sub

Sub LostFoscus()
 if me.Text <> fld_password.Text Then
   If haveFocus Then
       MsgBox "Not a good password."
   Else
       me.Text = ""
       fld_password.SetFocus()
   End if
 End if
 haveFocus=False
End Sub

--
Peter Bozek
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to