OnLostFocus Event - Problem with sequence of called functions
Posted: Tue Apr 05, 2016 3:01 pm
I need to create form with two textboxes, which values should be checked while focus loose.
I've prepared small sample - two fields, no one can not be empty. Program uses On LostFocus to test content of field. When is empty, message is generated.
Try to leave field 1 empty and observe messages
I've prepared small sample - two fields, no one can not be empty. Program uses On LostFocus to test content of field. When is empty, message is generated.
Try to leave field 1 empty and observe messages
Code: Select all
#include "hmg.ch"
Function Main
DEFINE WINDOW Form_Main ;
AT 0,0 ;
WIDTH 640 HEIGHT 600 ;
TITLE 'ON LOST FOCUS TEST' ;
MAIN
@ 100,10 LABEL L1 ;
WIDTH 150 HEIGHT 20 ;
VALUE 'FIELD 1'
@ 100,100 textbox T1 ;
WIDTH 150 HEIGHT 20 ;
VALUE '' ;
On lostfocus T1_CheckValue()
@ 130,10 LABEL L2 ;
WIDTH 150 HEIGHT 20 ;
VALUE 'FIELD 2'
@ 130,100 textbox T2 ;
WIDTH 150 HEIGHT 20 ;
VALUE '';
On lostfocus T2_CheckValue()
@ 180,10 LABEL L_Info1 ;
WIDTH 120 HEIGHT 18 ;
VALUE 'Focused control'
@ 200,10 LABEL L_Info ;
WIDTH 600 HEIGHT 380 ;
BACKCOLOR {255,255,0};
FONTCOLOR {255,0,0};
VALUE 'Info label'
END WINDOW
CENTER WINDOW Form_Main
ON KEY ESCAPE OF FORM_MAIN ACTION FORM_MAIN.RELEASE
ACTIVATE WINDOW Form_Main
Return
*----------------
function T1_CheckValue
Form_Main.L_Info.Value := hb_valtoexp(ThisWindow.FocusedControl) + ViewCallStack()
if empty(This.Value)
MsgStop("Field T1 can not be empty!" + chr(10)+"Focused control is: "+hb_valtoexp(ThisWindow.FocusedControl))
Form_Main.T1.SetFocus
endif
return .t.
*----------------
function T2_CheckValue
Form_Main.L_Info.Value := hb_valtoexp(ThisWindow.FocusedControl) + ViewCallStack()
if empty(This.Value)
MsgStop("Field T2 can not be empty!" + chr(10)+"Focused control is: "+hb_valtoexp(ThisWindow.FocusedControl))
Form_Main.T2.SetFocus
endif
return .t.
*-------------------
function ViewCallStack
local i := 2, cStack := ""
while ( !Empty(ProcName(i)) )
cStack += ProcName(i) + "(" + alltrim(str(ProcLine(i)) )+ ")"+" ---- "
i++
end
return cStack
*------------------