Just starting out? Need help? Post your questions and find answers here.
orangetek
 
Posts: 7
Joined: Fri Dec 08, 2017 2:32 pm

[SOLVED] Opening a window inside a callback?

by orangetek Thu Sep 26, 2019 6:13 am

Hi,

I'm stuck! I'm not sure how i should code the following scenario. As soon as my page opens, the first thing it does is send a http request to a server. I have verified this bit works and a result from the server is passed back to the httprequest callback. This bit also works and i can debug the result. I want to open my first window based on the value sent from the server but "openwindow()" does not seem to work from a callback or normal procedure. Is there a way to get the result to main loop from a callback? or am i going about it the wrong way?

Code: Select all
Procedure CloseWindowEvent()
 
  Debug "Closing window: " + EventWindow()
  CloseWindow(EventWindow())
 
EndProcedure

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
   
    Select Result$
      Case "LOGIN"
        OpenWindow(1,0,0,300,200,"Login")
       
    EndSelect
   
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure



HTTPRequest(#PB_HTTP_Get, "https://spacenetcy.net", "", @HttpGetEvent())
orangetek
 
Posts: 7
Joined: Fri Dec 08, 2017 2:32 pm

Re: [SOLVED] Opening a window inside a callback?

by orangetek Thu Sep 26, 2019 6:45 am

My server was sending a #CRLF$ at the end of the result so debugging the result was ok but the Case statement was not expecting it. I also found a simple way to use the result outside of the callback by calling another procedure.

Code: Select all
Procedure CloseWindowEvent()
 
  Debug "Closing window: " + EventWindow()
  CloseWindow(EventWindow())
 
EndProcedure

Procedure main(Result$)
 
  Debug Result$
  OpenWindow(0,0,0,300,500,"main")
  BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())

EndProcedure

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
   
    Select Result$
      Case "LOGIN"
        main(Result$)
       
    EndSelect
   
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure

HTTPRequest(#PB_HTTP_Get, "https://spacenetcy.net/POS", "", @HttpGetEvent())
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests