Page 1 of 1
GotFocus event
Posted: Tue Jul 28, 2009 8:40 am
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
Re: GotFocus event
Posted: Sat Aug 01, 2009 6:49 am
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
Re: GotFocus event
Posted: Sat Aug 01, 2009 5:05 pm
by Rathinagiri
Hi Sudip,
Can you please provide a small working sample?
Re: GotFocus event
Posted: Sun Aug 02, 2009 12:58 pm
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
Re: GotFocus event
Posted: Sun Aug 02, 2009 3:18 pm
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.
Re: GotFocus event
Posted: Sun Aug 02, 2009 3:45 pm
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
Re: GotFocus event
Posted: Sun Aug 02, 2009 4:07 pm
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.

Re: GotFocus event
Posted: Mon Aug 03, 2009 3:37 am
by sudip
Thank you friend

Regards.
Sudip