Page 1 of 2

Weird Behavior of OnLostFocus

Posted: Thu Jul 19, 2012 2:49 pm
by Rathinagiri
Please consider these two examples:

Code: Select all

#include <hmg.ch>

Function Main
   define window x at 0, 0 width 300 height 300 main
      define textbox t1
         row 10
         col 10
         width 100
         onlostfocus msginfo( 'T1 Lostfocus' )
         tooltip 't1' 
      end textbox   
      define textbox t2
         row 40
         col 10
         width 100
         tooltip 't2' 
      end textbox   
      define textbox t3
         row 70
         col 10
         width 100
         onlostfocus msginfo( 'T3 Lostfocus' )
         tooltip 't3' 
      end textbox   
   end window
   x.center
   x.activate   
Return

Code: Select all

#include <hmg.ch>

Function Main
   define window x at 0, 0 width 300 height 300 main
      define textbox t1
         row 10
         col 10
         width 100
         onlostfocus msginfo( 'T1 Lostfocus' )
         tooltip 't1' 
      end textbox   
      define textbox t2
         row 40
         col 10
         width 100
         onlostfocus msginfo( 'T2 Lostfocus' )
         tooltip 't2' 
      end textbox   
      define textbox t3
         row 70
         col 10
         width 100
         tooltip 't3' 
      end textbox   
   end window
   x.center
   x.activate   

Return
When T1, T2 and T3 are lost focus please check the messages shown. I don't know why this happen.

Re: Weird Behavior of OnLostFocus

Posted: Thu Jul 19, 2012 4:17 pm
by Pablo César
Dear Rathinagiri,

I have noted your codes exemples and in my opinion the cause of this malfunction is due the click or even enter after msginfo as interpreted as new event which certainly is positioned out of range of textboxes and then interprets as onlostfocus. So I make someadjustings to show you that is nothing wrong with onlostfocus events.

Code: Select all

#include <hmg.ch>

Function Main
   define window x at 0, 0 width 300 height 300 main
      define textbox t1
         row 10
         col 10
         width 100
         onlostfocus ShowMsg( This.name )
         tooltip 't1' 
      end textbox   
      define textbox t2
         row 40
         col 10
         width 100
         onlostfocus ShowMsg( This.name )
         tooltip 't2' 
      end textbox   
      define textbox t3
         row 70
         col 10
         width 100
         tooltip 't3' 
      end textbox   
	  DEFINE STATUSBAR FONT "Courier New" SIZE 9
		STATUSITEM ""
      END STATUSBAR
   end window
   x.center
   x.activate   

Return

Function ShowMsg(cWhich)
x.StatusBar.Item(1) :=  cWhich+' Lostfocus' 
Return Nil
I hope to be usefull to clear in your problem.

Re: Weird Behavior of OnLostFocus

Posted: Thu Jul 19, 2012 4:40 pm
by Rathinagiri
Hi Pablo César,

Thanks for your explanation. Now I understand! :) Sorry for false alarm. :(

Re: Weird Behavior of OnLostFocus

Posted: Fri Jul 20, 2012 2:36 am
by Pablo César
Ohhh please do not mentioned it !

All questions serves for our own knowledge ! Your are always, wellcome !

Re: Weird Behavior of OnLostFocus

Posted: Thu Sep 13, 2012 10:53 am
by Jayesh
So, is it not practicable to use onlostfocus function in our programs as it would have been very much useful for validity checking of input data ? Is there any solution ?

Regards.

Re: Weird Behavior of OnLostFocus

Posted: Thu Sep 13, 2012 4:11 pm
by Rathinagiri
Hi,

It is not against the usage of OnLostFocus. The culprit is MsgInfo() function which simulates the lostfocus events of various textboxes. If you use status bar/labels to give message, we can very well use OnLostFocus.

Re: Weird Behavior of OnLostFocus

Posted: Sun Sep 16, 2012 2:23 pm
by Jayesh
Thanks Rathi (once again) for replying. Msginfo function would have been very useful if it would have been worked 'ok' from lostfocus event. I also experienced same problem (?) using getfocus. OK, i'll try labels to display messages.

Regards.

Re: Weird Behavior of OnLostFocus

Posted: Mon Sep 17, 2012 10:09 am
by Jayesh
Hi rathi,

one more question. Is it possible to use 'common function' to display error messages using 'common label name' in all programs.
I am defining new label named lbl_dsperr in all data entry programs. Now i want to write common function to display message.
eg.
function disperr()
thiswindow.lbl_dsperr.value := "this is a error"
mSec := seconds()
do while seconds() - mSec < 4
enddo
thiswindow.lbl_dsperr.hide
return nil

i am getting syntax error while compling this function.

i am getting compilation error for this function

Re: Weird Behavior of OnLostFocus

Posted: Mon Sep 17, 2012 10:45 am
by Rathinagiri
That is a nice idea. :) Even you can pass on an internal error code to display various types of errors.

Kindly change your function like one below:

function disperr()
local cFormName := thiswindow.name
local cControlName := 'lbl_dsperr'
setProperty( cFormname, cControlName, 'VALUE', 'This is an error.' )
mSec := seconds()
do while seconds() - mSec < 4
enddo
setProperty( cFormname, cControlName, 'VALUE', '' )
// thiswindow.lbl_dsperr.hide
return nil

Re: Weird Behavior of OnLostFocus

Posted: Wed Sep 19, 2012 4:42 am
by Jayesh
Thanks a lot Rathi. It worked.