It is currently Sat Dec 16, 2017 7:32 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 1:18 am 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 22, 2011 5:11 pm
Posts: 173
Location: Kelowna, BC, Canada
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:
  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.61 on Windows 10 & OS X Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 10:44 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jun 01, 2012 12:20 am
Posts: 124
I cant run the code

Constant not found #Form_Login


Top
 Profile  
Reply with quote  
 Post subject: Re: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 12:30 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10312
Location: Beyond the pale...
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 7:47 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 22, 2011 5:11 pm
Posts: 173
Location: Kelowna, BC, Canada
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.61 on Windows 10 & OS X Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 8:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 22, 2011 5:11 pm
Posts: 173
Location: Kelowna, BC, Canada
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:
  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.61 on Windows 10 & OS X Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: 2nd eventloop for login screen
PostPosted: Sun Nov 19, 2017 8:25 pm 
Offline
Enthusiast
Enthusiast

Joined: Tue Nov 22, 2011 5:11 pm
Posts: 173
Location: Kelowna, BC, Canada
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.61 on Windows 10 & OS X Sierra


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye