Hi Tomfromdare
I see myself in you.

Yes. I had asked almost all these questions before jumping into the GUI stream!
Then, I learned from the samples/examples provided by Roberto.
GUI is just event driven. It is like dinner with all the items already served on the plate. The user can take anyone he wants in any order he wishes.
Take your case, a login screen.
Please consider this small sample: (It's not complete though)
Code: Select all
function showlogin()
private nTries := 0
private nMaxTriesAllowed := 3
lAuthenticated := .f.
define login at 0,0 width 200 height 200 modal
define label usernamelabel
row 10
col 10
width 80
value "User ID"
end label
define textbox userid
row 10
col 90
width 80
value ""
maxlength 10
end textbox
define label passlabel
row 40
col 10
width 80
value "Password"
end label
define textbox pass
row 40
col 90
width 80
value ""
password .t.
end textbox
define button loginok
row 70
col 10
caption "Login"
width 80
action dologin()
end button
define button close
row 70
col 110
width 80
caption "Exit"
action login.release()
end button
end window
login.center
login.activate
return nil
Once you login window is activated using login.activate, a window with two labels and two textboxes are shown. The user enters the user-id and password and clicks login. Immediately the control is transferred to dologin() function. In dologin() function, we have to check the username and password for authentication. If it is right, then we can release the login window. Otherwise, we can just return back.
See this function...
Code: Select all
function dologin
if login.userid.value == "Correct User" and login.pass.value == "Correct Password"
lAuthenticated := .t.
login.release()
else
nTries := nTries + 1
if nTries > nMaxTriesAllowed
msgstop("Wrong credentials! You have to restart!")
lAuthenticated := .f.
login.release()
else
msgstop("Invalid Username/Password! Please try again.")
login.userid.value := ""
login.pass.value := ""
endif
endif
return nil
Since login window is a modal window, the user can not access any other window than this. If he succeeded, login window will be closed with lAuthenticated := .t. Otherwise, lAuthenticated := .f. which can be verified from the calling function.
I think I had not confused you.
