2nd eventloop for login screen

Just starting out? Need help? Post your questions and find answers here.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

2nd eventloop for login screen

Post by kpeters58 »

I added a login dialog to one of my bigger apps which works very well when running in the IDE. As soon as I create a standalone exe, it seems to hang in the event loop of the procedure below (as far as I can tell by now); my app also has another (main) event loop - I use this one to create a modal login window. What am I doing wrong?

Code: Select all

  Procedure PerformLogin()
    Protected Button_Cancel, Button_Login
    
    If OpenWindow(#Form_Login, #PB_Ignore, #PB_Ignore,  300, 150, " " + VersionInfo\ProductName + " - " + Language("Main", "LogInCaption"), #PB_Window_Tool | #PB_Window_ScreenCentered)
      ActiveSubWindowCount + 1
      Macros::FontStyleNormal  
      ;
      String_Username = StringGadget(#PB_Any, 150,  30, 110,  20, "")
      String_Password = StringGadget(#PB_Any, 150,  70, 110,  20, "", #PB_String_Password)
      TextGadget(#PB_Any, 50, 30, 90, 20, Language("Main", "UserName"), #PB_Text_Right)
      TextGadget(#PB_Any, 50, 70, 90, 20, Language("Main", "Password"), #PB_Text_Right)
      Button_Cancel   = ButtonGadget(#PB_Any,  80, 110,  85,  25, Language("Shared", "Cancel")): GadgetToolTip(Button_Cancel, Language("Main", "HintCancel"))
      Button_Login    = ButtonGadget(#PB_Any, 175, 110,  85,  25, Language("Main",   "LogIn")):  GadgetToolTip(Button_Login,  Language("Main", "HintLogin"))
    EndIf
    StickyWindow(#Form_Login, #True)
    SetActiveGadget(String_Username)
    Repeat                          
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          ActiveSubWindowCount - 1
          CloseWindow(#Form_Login)
          Break
        Case #PB_Event_Gadget
          If EventGadget() = Button_Cancel
            ActiveSubWindowCount - 1
            LoggedIn = #False
            CloseWindow(#Form_Login)
            Break
          ElseIf EventGadget() = Button_Login
            LoggedIn = AttemptLogin()
            If LoggedIn
              ActiveSubWindowCount - 1
              CloseWindow(#Form_Login)
              Break
            EndIf  
          EndIf
      EndSelect
    ForEver
  EndProcedure
PB 5.73 on Windows 10 & OS X High Sierra
acreis
Enthusiast
Enthusiast
Posts: 182
Joined: Fri Jun 01, 2012 12:20 am

Re: 2nd eventloop for login screen

Post by acreis »

I cant run the code

Constant not found #Form_Login
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: 2nd eventloop for login screen

Post by srod »

I just inserted your code into a program of mine in which your code runs in response to an event in a main event loop and whilst I don't like the way you've set this up, it runs fine, both in the IDE and as a standalone exe (Win 7, x64 exe). Obviously I changed a few things so that it would compile.

Either there is something you've left out or, perhaps, something wrong elsewhere in your code. Are you absolutely sure the program is hanging in this procedure (presumably an infinite loop)? If it is, try outputting the value of EventWindow() after every WaitWindowEvent() to see which window is generating events. You might try disabling the main window during this procedure.
I may look like a mule, but I'm not a complete ass.
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: 2nd eventloop for login screen

Post by kpeters58 »

srod wrote:I just inserted your code into a program of mine in which your code runs in response to an event in a main event loop and whilst I don't like the way you've set this up, it runs fine, both in the IDE and as a standalone exe (Win 7, x64 exe).
While I am trying to figure out what is going on: Would you mind sharing the way you would have set this up - I am always looking to improve my code?
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: 2nd eventloop for login screen

Post by kpeters58 »

Found the issue - don't understand it (yet), though.....

Had added an image of a locked padlock to the login screen which I replace with the image of an unlocked padlock upon successful login. I had added a 1 second delay after that so that users could see it. If I remove the delay, all is fine both in the IDE and standalone. With the delay in place, the login form hangs and my main form does not show when running as standalone exe....

Code: Select all

  Procedure AttemptLogin()
    Protected username.s, password.s
    
    LoggedIn = #False
    username = Trim(GetGadgetText(String_Username))
    password = Trim(GetGadgetText(String_Password))
    If Len(username) = 0
      MessageRequester(Language("Shared", "Information"), Language("Main", "NeedUsername"), #PB_MessageRequester_Info)
      SetActiveGadget(String_Username)
      ProcedureReturn
    EndIf
    If Len(password) = 0
      MessageRequester(Language("Shared", "Information"), Language("Main", "NeedPassword"), #PB_MessageRequester_Info)
      SetActiveGadget(String_Password)
      ProcedureReturn
    EndIf
    If DBLib::Authenticate(username, password)
      LoggedIn = #True
      SetGadgetState(Image_Lock, ImageID(#LockOpen))
      Delay(1000)
      ProcedureReturn
    Else
      MessageRequester(Language("Shared", "Information"), Language("Main", "NotAuthorized"), #PB_MessageRequester_Info)
    EndIf      
  EndProcedure
PB 5.73 on Windows 10 & OS X High Sierra
User avatar
kpeters58
Enthusiast
Enthusiast
Posts: 341
Joined: Tue Nov 22, 2011 5:11 pm
Location: Kelowna, BC, Canada

Re: 2nd eventloop for login screen

Post by kpeters58 »

If I remove the delay call from the AttemptLogin procedure and move it into the Event loop of PerformLogin, everything works perfectly inside the IDE and standalone as well!
PB 5.73 on Windows 10 & OS X High Sierra
Post Reply