- Offizieller Beitrag
Wenn ich in AutoIt den OnEventMode verwende, dann gibt es ja auch eine "MainLoop":
AutoIt
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
Global $bStart = False, $iCount = 0
Global $hGui = GUICreate("Test", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGui")
Global $idLabel = GUICtrlCreateLabel($iCount, 10, 10, 380, 20)
Global $idButton = GUICtrlCreateButton('Start/Stop', 10, 50, 100, 25)
GUICtrlSetOnEvent(-1, '_Start')
GUISetState(@SW_SHOW)
; MainLoop
While Sleep(100)
If $bStart Then
$iCount += 1
GUICtrlSetData($idLabel, $iCount)
EndIf
WEnd
Func _CloseGui()
Exit
EndFunc ;==>_CloseGui
Func _Start()
$bStart = Not $bStart
EndFunc ;==>_Start
Alles anzeigen
Wenn ich das Gleiche aber in Nim machen will, dann klappt das nicht (Absturz):
Code
import wNim
import os
var
bStart: bool = false
iCount: int = 0
let app = App()
let frame = Frame(title="Test", size=(400, 300))
let panel = Panel(frame)
let idLabel = StaticText(panel, label= $iCount, pos=(10, 10), size=(380, 20))
let idButton = Button(panel, label="Start/Stop", pos=(10, 50), size=(100, 25))
idButton.wEvent_Button do (): bStart = not bStart
frame.center()
frame.show()
app.mainLoop() # wenn ich das auskommentiere, dann stuerzt das Programm ab
# das reicht wohl nicht als "MainLoop"!?
while true:
sleep(100)
if bStart == true:
iCount += 1
idLabel.label = $iCount
Alles anzeigen
Was passiert denn da noch in "app.mainLoop"?