我在脚本的开头定义了一个线程派生类:
class procthread : thread
{
......
object init( object self)
{
...
}
void RunThread( object self )
{
.....
}
}
然后是 MyDialog 类,它应该使用这个线程:
Class MyDialog: UIFrame
{
object wrkthread
.....
TagGroup CreateMyDialog(Object self, number nref)
{
........
btn0=DLGCreatePushButton("+","DoBut0").DLGIdentifier("#PushB0")
wrkthread=alloc(procthread) ////<----- works
return DialogTG
}
Object Init(Object self, number nref) return self.super.Init(self.CreateMyDialog(nref))
Void DoBut0(Object self)
{
wrkthread=alloc(procthread) ////<---- does not work
}
}
根据脚本的逻辑,每次按下按钮时都应该分配和激活线程。然而,在 on_button_pressed 处理程序中调用的“wrkthread=alloc(procthread)”会引发异常“找不到类 'procthread'”。同时,来自 Init 函数的相同调用运行良好并且线程运行。
这里有什么问题?我不敢相信类定义仅在主线程中可见,这没有任何意义。
如果我犯了错误,你能纠正吗?如果这是一个功能 - 如何绕过它?