Rathi,
is lostfocus event not work well with 'Setfocus' method ? I am experiencing some problem using 'Setfocus' in lostfocus event.
Can u help me plz ?
My sample code is as above , I want to setfocus of text_1 field if text_2 value is 100
Thanks in advance.
#include "hmg.ch"
*
Function Main
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 940 HEIGHT 480 ;
TITLE 'Lostfocus Test' ;
MAIN
@ 10,10 LABEL lbl_ERRMSG ;
VALUE ""
@ 110,10 TEXTBOX Text_1 ;
VALUE 123 ;
NUMERIC ;
ON LOSTFOCUS SHOWMSG1("text_1")
@ 150,10 TEXTBOX Text_2 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_2")
@ 200,10 TEXTBOX Text_3 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_3")
END WINDOW
Form_1.Center
Form_1.Activate
Return Nil
*******************************
FUNCTION SHOWMSG1(mxErrMsg)
mtmp := space(10)
mxyWindName := ThisWindow.Name
mxyCntrName := "Lbl_ERRMSG"
SetProperty(mxyWindName,mxyCntrName,"Value","Displaying "+mxErrMsg)
mxSec := Seconds()
DO WHILE (Seconds() - mxSec) < 1
ENDDO
SetProperty(mxyWindName,mxyCntrName,"Value","")
*
mTmpVal := Form_1.Text_2.value
IF (mxErrMSg = "text_2") .and. (mTmpVal = 100)
mxyCntrName := "Text_2"
DOMETHOD(mxyWindName,mxyCntrName,"SetFocus")
ENDIF
*
RETURN NIL
**********************************
Weird Behavior of OnLostFocus
Moderator: Rathinagiri
- Pablo César
- Posts: 4059
- Joined: Wed Sep 08, 2010 1:18 pm
- Location: Curitiba - Brasil
Re: Weird Behavior of OnLostFocus
Some changings was necessary, please note corrections:
Code: Select all
#include "hmg.ch"
*
Function Main
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 940 HEIGHT 480 ;
TITLE 'Lostfocus Test' ;
MAIN
@ 10,10 LABEL lbl_ERRMSG ;
VALUE ""
@ 110,10 TEXTBOX Text_1 ;
VALUE 123 ;
NUMERIC ;
ON LOSTFOCUS SHOWMSG1("text_1")
@ 150,10 TEXTBOX Text_2 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_2")
@ 200,10 TEXTBOX Text_3 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_3")
END WINDOW
Form_1.Center
Form_1.Activate
Return Nil
FUNCTION SHOWMSG1(mxErrMsg)
// mtmp := space(10)
// mxyWindName := ThisWindow.Name
// mxyCntrName := "Lbl_ERRMSG"
SetProperty("Form_1","Lbl_ERRMSG","Value","Displaying "+mxErrMsg)
mxSec := Seconds()
DO WHILE (Seconds() - mxSec) < 1
ENDDO
SetProperty("Form_1","Lbl_ERRMSG","Value","")
*
mTmpVal := Form_1.Text_2.value
IF (mxErrMSg = "text_2") .and. (mTmpVal = 100)
// mxyCntrName := "Text_2"
DOMETHOD("Form_1","text_1","SetFocus")
ENDIF
*
RETURN NIL
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Re: Weird Behavior of OnLostFocus
Thanks Pablo César for prompt reply.
Sorry, it's my mistake that i haven't given the exact problem that i'm facing using lostfocus. i want to use 'Setfocus' in 'lostfocus' event. In my sample program, i want to take back control from text_2 to text_1 if the value entered in text_2 is 100. The problem is that after punching 100 in text2 it first displays the message of text_3 (plz. check display label) and then cursor goes to text_1. Pablo, I tried ur code, but it gives the same problem.
Plz. help.
Regards.
Sorry, it's my mistake that i haven't given the exact problem that i'm facing using lostfocus. i want to use 'Setfocus' in 'lostfocus' event. In my sample program, i want to take back control from text_2 to text_1 if the value entered in text_2 is 100. The problem is that after punching 100 in text2 it first displays the message of text_3 (plz. check display label) and then cursor goes to text_1. Pablo, I tried ur code, but it gives the same problem.
Plz. help.
Regards.
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Weird Behavior of OnLostFocus
Hi,
In your code,
mxyCntrName := "Text_2"
Should be,
mxyCntrName := "Text_1"
Regarding the message of 'text_3', there is no intermediate state in windows. ie., after the control is lostfocus in text2, text3 will get focus immediately since that is the next control in the tab order. Now, if you don't want to process the whole procedure for text3 lostfocus event, we can do it manually. Please consider the following code:
In your code,
mxyCntrName := "Text_2"
Should be,
mxyCntrName := "Text_1"
Regarding the message of 'text_3', there is no intermediate state in windows. ie., after the control is lostfocus in text2, text3 will get focus immediately since that is the next control in the tab order. Now, if you don't want to process the whole procedure for text3 lostfocus event, we can do it manually. Please consider the following code:
Code: Select all
#include "hmg.ch"
*
Function Main
public lText3Focus := .f.
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 940 HEIGHT 480 ;
TITLE 'Lostfocus Test' ;
MAIN
@ 10,10 LABEL lbl_ERRMSG ;
VALUE ""
@ 110,10 TEXTBOX Text_1 ;
VALUE 123 ;
NUMERIC ;
ON LOSTFOCUS SHOWMSG1("text_1")
@ 150,10 TEXTBOX Text_2 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_2")
@ 200,10 TEXTBOX Text_3 ;
VALUE 123 ;
Numeric ;
ON LOSTFOCUS SHOWMSG1("text_3")
END WINDOW
Form_1.Center
Form_1.Activate
Return Nil
*******************************
FUNCTION SHOWMSG1(mxErrMsg)
if lText3Focus
return nil
endif
mtmp := space(10)
mxyWindName := ThisWindow.Name
mxyThisCntr := This.Name
mxyCntrName := "Lbl_ERRMSG"
if upper( mxyThisCntr ) == 'TEXT_2'
lText3Focus := .t.
else
lText3Focus := .f.
endif
SetProperty(mxyWindName,mxyCntrName,"Value","Displaying "+mxErrMsg)
mxSec := Seconds()
DO WHILE (Seconds() - mxSec) < 1
ENDDO
SetProperty(mxyWindName,mxyCntrName,"Value","")
*
mTmpVal := Form_1.Text_2.value
IF (mxErrMSg = "text_2") .and. (mTmpVal = 100)
mxyCntrName := "Text_1"
DOMETHOD(mxyWindName,mxyCntrName,"SetFocus")
ENDIF
*
RETURN NIL
**********************************
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.