简单定时器实现
; 示例 #4: 使用 method 作为定时器子程序.
counter := new SecondCounter
counter.Start()
Sleep 5000
counter.Stop()
Sleep 2000
; 一个记录秒数的示例类...
class SecondCounter {
__New() {
this.interval := 1000
this.count := 0
; Tick() 有一个隐式参数 "this" 引用一个对象
; 所以
; 我们需要创建一个封装 "this" 和 Tick 方法的函数来调用:
this.timer := ObjBindMethod(this, "Tick")
}
Start() {
; 已知限制: SetTimer 需要一个纯变量引用.
timer := this.timer
SetTimer % timer, % this.interval
ToolTip % "Counter started"
}
Stop() {
; 在此之前传递一个相同的对象来关闭定时器:
timer := this.timer
SetTimer % timer, Off
ToolTip % "Counter stopped at " this.count
}
; 本例中,定时器调用了以下方法:
Tick() {
ToolTip % ++this.count
}
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

