Weird Behavior of OnLostFocus

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Weird Behavior of OnLostFocus

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Weird Behavior of OnLostFocus

Post 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.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
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

Post by Rathinagiri »

Hi Pablo César,

Thanks for your explanation. Now I understand! :) Sorry for false alarm. :(
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Re: Weird Behavior of OnLostFocus

Post by Pablo César »

Ohhh please do not mentioned it !

All questions serves for our own knowledge ! Your are always, wellcome !
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Jayesh
Posts: 36
Joined: Fri Apr 01, 2011 4:46 pm

Re: Weird Behavior of OnLostFocus

Post 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.
User avatar
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

Post 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.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Jayesh
Posts: 36
Joined: Fri Apr 01, 2011 4:46 pm

Re: Weird Behavior of OnLostFocus

Post 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.
Jayesh
Posts: 36
Joined: Fri Apr 01, 2011 4:46 pm

Re: Weird Behavior of OnLostFocus

Post 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
User avatar
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

Post 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
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Jayesh
Posts: 36
Joined: Fri Apr 01, 2011 4:46 pm

Re: Weird Behavior of OnLostFocus

Post by Jayesh »

Thanks a lot Rathi. It worked.
Post Reply