none
How to Call Login form from main.prg

    Question

  • Hello Experts

    I know this may be a rather simple one, but its my first time creating a Login form and Id like to have it start up before any other form or forms called in my PRG

    thanks

    Mike

    Tuesday, March 05, 2013 4:15 PM

Answers

  • You'd just start it as you would expect, via Do Form command, or NewObject() / CreateObject() if it's a class instead of an SCX form.

    Details would depend on whether the VFP "main screen" a.k.a. _screen is visible when your.EXE is starting:

    If it is, you can make the LoginForm modal, and then either use the "Do Form xy To result" syntax in order to return either log-in success or failure.

    Or do a "Thisform.Hide()" instead of "Thisform.Release()" in loginForm.closeButton.Click() and QueryUnload() - that way the calling code can read something like a custom property as a return value because the loginForm object would still exist when the calling code gets past the "Do Form modalForm" wait state

    Or create a parameter object and pass it to the LoginForm, receive it in LoginForm.Init(), store it in a LoginForm.oParameter custom property, and assign success values to Thisform.oParameter.customProperty

    Whereas if _screen is not visible, LoginForm needs to have ShowWindow=2 && As Top-Level, so that it cannot be modal.
    In that case you can have two "Read Events" lines in your "main.PRG" - one after the "Do form LoginForm" line, having a corresponding "Clear Events" in a place like LoginForm.Destroy(), and the other one would be later, the one that you probably already have in your code as usual, say after your "Do Form MainForm" and/or "Do myMenu.MPR" have run

    hth
    -Stefan



    • Edited by Stefan Wuebbe Tuesday, March 05, 2013 6:50 PM
    • Marked as answer by mikelvfp Tuesday, March 05, 2013 7:15 PM
    Tuesday, March 05, 2013 6:46 PM

All replies

  • You'd just start it as you would expect, via Do Form command, or NewObject() / CreateObject() if it's a class instead of an SCX form.

    Details would depend on whether the VFP "main screen" a.k.a. _screen is visible when your.EXE is starting:

    If it is, you can make the LoginForm modal, and then either use the "Do Form xy To result" syntax in order to return either log-in success or failure.

    Or do a "Thisform.Hide()" instead of "Thisform.Release()" in loginForm.closeButton.Click() and QueryUnload() - that way the calling code can read something like a custom property as a return value because the loginForm object would still exist when the calling code gets past the "Do Form modalForm" wait state

    Or create a parameter object and pass it to the LoginForm, receive it in LoginForm.Init(), store it in a LoginForm.oParameter custom property, and assign success values to Thisform.oParameter.customProperty

    Whereas if _screen is not visible, LoginForm needs to have ShowWindow=2 && As Top-Level, so that it cannot be modal.
    In that case you can have two "Read Events" lines in your "main.PRG" - one after the "Do form LoginForm" line, having a corresponding "Clear Events" in a place like LoginForm.Destroy(), and the other one would be later, the one that you probably already have in your code as usual, say after your "Do Form MainForm" and/or "Do myMenu.MPR" have run

    hth
    -Stefan



    • Edited by Stefan Wuebbe Tuesday, March 05, 2013 6:50 PM
    • Marked as answer by mikelvfp Tuesday, March 05, 2013 7:15 PM
    Tuesday, March 05, 2013 6:46 PM
  • Thanks Stefan,

    I followed your second suggestion

    Or do a "Thisform.Hide()" instead of "Thisform.Release()" in loginForm.closeButton.Click() and QueryUnload() - that way the calling code can read something like a custom property as a return value because the loginForm object would still exist when the calling code gets past the "Do Form modalForm" wait state

    where the _screen is visible at login time and it works

    I need to run some more tests though but for now it works like it should

    thanks

    Mike

    Tuesday, March 05, 2013 7:15 PM
  • You're welcome. Must admit that my reply was a little nutshell'ish since I was not sure what details you'd want to focus on

    -Stefan

    Tuesday, March 05, 2013 7:19 PM
  • I would say the same about myself as i didnt give enough detail

    thank Stefan

    Tuesday, March 05, 2013 7:21 PM