GotFocus event

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

GotFocus event

Post by sudip »

Hi All,

If I'm not wrong, GOTFOCUS event of a Window fires:
1) When the window gets focus.
2) When one control of the window gets focus from another control of the SAME WINDOW.

When I am working on DBF files, I am storing workarea, record number, index order etc in an array before window losing focus and restoring those values from the array when window getting focus. So, if 2nd point of GOTFOCUS and LOSTFOCUS behavior is correct, then program will become slow. Especially when we want to refresh COMBOBOX (more than one) for master file lookup using GOTFOCUS event of window to synchronize changes in master files.

Hope I am able to express my points clearly :)

With best regards.

Sudip
With best regards,
Sudip
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: GotFocus event

Post by sudip »

Hello Friends,

In which window event should we refresh a combo box for a foreign key of a data entry form?

Thanks in advance.

With best regards.

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

Re: GotFocus event

Post by Rathinagiri »

Hi Sudip,

Can you please provide a small working sample?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: GotFocus event

Post by sudip »

Hello Rathi,

I just created a small sample code to show how GotFocus event of the window occurs number of controls of the windows, each time window is getting focus.

This small code also shows that my previous 2nd point, i.e.,
sudip wrote:2) When one control of the window gets focus from another control of the SAME WINDOW.
is wrong. :)

Code: Select all

#include "minigui.ch"

function Main()

	local i := 1, tb, lb
	
	define window winMain at 0, 0 width 600 height 400 title "GotFocus Testing" main ;
		on gotfocus WinGotfocus()
	
		do while i*30 < 350
			lb := "Label_"+ltrim(str(i))
			tb := "Text_"+ltrim(str(i))
			@ i*30, 10 label &lb value (lb)
			@ i*30, 100 textbox &tb
			i++
		enddo
	
	end window
	
	winMain.center()
	winMain.activate()
	return nil
	
	
function WinGotFocus()
	msgbox("Windows GotFocus")
	return nil	
Please compile and run above code.

So, if we want to place code for refreshing list of lookup items for a combobox with in GotFocus control of a window, it will fire several times and will make the program run slow.

Please check.

TIA.

Regards.

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

Re: GotFocus event

Post by Rathinagiri »

Hi Sudip,

Please try this modified code.

Code: Select all

    #include "minigui.ch"

    function Main()

       local i := 1, tb, lb
       public count := 0
       
       define window winMain at 0, 0 width 600 height 400 title "GotFocus Testing" main ;
          on gotfocus WinGotfocus()
          @ 10,250 label countlabel width 300 value ""
          do while i*30 < 350
             lb := "Label_"+ltrim(str(i))
             tb := "Text_"+ltrim(str(i))
             @ i*30, 10 label &lb value (lb)
             @ i*30, 100 textbox &tb
             i++
          enddo
       
       end window
       
       winMain.center()
       winMain.activate()
       return nil
       
       
    function WinGotFocus()
       count := count + 1
       winmain.countlabel.value := "Total windows got focus count:"+str(count)
//       msgbox("Windows GotFocus")
       return nil   
By this, you can understand that, the windows got focus event had been fired only once. :)

Then why yours take 17 times? It is because, every time you call msgwindow, the focus is transferred to message window. So, when you press the ok button, again the main window is getting focus.

IMHO, it won't be fired a lot of times, if the focus is maintained within the window frame inside our program.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: GotFocus event

Post by sudip »

rathinagiri wrote: ...
...
By this, you can understand that, the windows got focus event had been fired only once. :)

Then why yours take 17 times? It is because, every time you call msgwindow, the focus is transferred to message window. So, when you press the ok button, again the main window is getting focus.

IMHO, it won't be fired a lot of times, if the focus is maintained within the window frame inside our program.
Thank you Rathi. Now I understand the behavior of GotFocus event of Windows. Only one doubt, in my previous code window is getting focus again and again when we click on ok button of MsgBox(). Then it should be within a infinite loop, why 17 (or any fixed number)? It is just for academic curiosity. My problem already solved from your last message :)
Regards.
Sudip
With best regards,
Sudip
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: GotFocus event

Post by Rathinagiri »

Actually it enters into an infinite loop. After 16 times, it seems like, the program is crashed and no message is shown in the message box.

I don't know how and why it is recovered from the loop. ;)
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: GotFocus event

Post by sudip »

Thank you friend :)
Regards.
Sudip
With best regards,
Sudip
Post Reply