Crazy double event

Mac OSX specific forum
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Crazy double event

Post by michel51 »

Hi All,

if I run the code, I get a double event.
That is, what it has to do:
Click on the left gadget, fill with "x". Click on the right gadget for example, fill the gadget with "X" and dont change the other gadgets. Click on left gadget will clear it.
The first click works fine, but the second click suddely produces a 2. event, what is the same as the one from the click before. But I don't know, from where it comes.

Code: Select all


If OpenWindow(0, 50, 50, 200, 200, #PB_Window_SystemMenu, "") = 0
    MessageRequester("Info"," Konnte das Fenster nicht oeffnen!"+#CRLF$+"Das Programm wird beendet.")
    End
EndIf

CreateGadgetList(WindowID(0))

StringGadget(0, 30, 30, 20, 20, "")
StringGadget(1, 50, 30, 20, 20, "")
StringGadget(2, 70, 30, 20, 20, "")

Repeat
    EventID = WaitWindowEvent()
    
    If EventID = #PB_Event_Gadget

        EVGID = EventGadgetID()
        Debug "EVGID: "+Str(EVGID)
        If GetGadgetText(EVGID) = ""
            SetGadgetText(EVGID,"x")

        Else
            SetGadgetText(EVGID,"")

        EndIf

    EndIf
  
Until EventID = #PB_EventCloseWindow

End
See the debugger-output, what happens.
Is this a bug on Mac or bad code?
I cannot stop it.
Or become I senile?

Hope, that there are a lot of Mac-User to help :)

michel51
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Hi michel51
When you activate or use "SetGadgetText(Bla)" you fire a new event.
if you don't whant that event, you can flush that event by using this line:

Code: Select all

 While WindowEvent():Wend
I i changed your Main loop to make it more clear:

Code: Select all


Repeat
    EventID = WaitWindowEvent()
    GadgetID = EventGadgetID()

 If EventID = #PB_EventGadget
        
        If GadgetID = 0
            Debug "EVGID: "+Str(GadgetID)            
            If GetGadgetText(0) = ""
                SetGadgetText(0,"x")
            EndIf
            While WindowEvent():Wend
            
        ElseIf GadgetID = 1
            Debug "EVGID: "+Str(GadgetID)
            While WindowEvent():Wend
            
        ElseIf GadgetID = 2
            Debug "EVGID: "+Str(GadgetID)
            While WindowEvent():Wend
            
        EndIf
        
    EndIf 
Until EventID = #PB_EventCloseWindow
** Edit ** Ups copied wrong code, corected now
Hope this works on Mac too :?
Best Henrik
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Post by michel51 »

Hi Henrik

Code: Select all

 While WindowEvent():Wend
It works :D

Many thanks.

michel51
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

:D
Nice to know that Mac = Win when useing PB own commands, and it should be like this btw.
So you should be able to use most of the codesnips around here as long as it's Api free :wink:

Best Henrik
Post Reply