What's the difference for the two methods of UI initiator?
I'd like to create sub-dialog. By using the first code below, I can correctly achieve my requirement. The sub dialogue will only appear when I click the button.
But if I use the second code, which using the constructor, the sub dialogue will appear when I run the script.
What's the difference for these two method?
Also: Running the 3rd example gives me an error. Why?
Class MySub:UIFrame
{
Object Init(Object self)
{
TagGroup DLGitems = DLGCreateDialog("Sub")
TagGroup RadioList=DLGCreateRadioList()
RadioList.DLGAddRadioItem("option 1",1)
RadioList.DLGAddRadioItem("option 2",2)
RadioList.DLGAddRadioItem("option 3",3)
DLGitems.DLGAddElement(RadioList)
Return self.super.Init(DLGitems)
}
}
Class MyMain:UIFrame
{
Object SubDialog
Void CallSubDialog(Object self)
{
Result("\nOpen sub-dialog.")
SubDialog.Pose() // call the local object
self.LookUpElement("Label").DLGTitle("option chosen")
}
Object Init(Object self, Object SDpass)
{
SubDialog = SDpass // Keep the object in a local variabl
TagGroup DLGitems = DLGCreateDialog("Main")
DLGitems.DLGAddElement(DLGCreateLabel("choose option").DLGIdentifier("Label"))
DLGitems.DLGAddElement(DLGCreatePushButton("Options","CallSubDialog"))
Return self.super.Init(DLGitems)
}
}
Object SubDialogOBJ = Alloc(MySub).Init() // Initialize the sub-dialog object in the main script
Object DialogOBJ = Alloc(MyMain).Init(SubDialogOBJ) // Pass on the object into the other
DialogOBJ.Display("Dialog")
Class MySub:UIFrame
{
TagGroup gen_MySubUI_dlg(Object self)
{
TagGroup DLGitems = DLGCreateDialog("Sub")
TagGroup RadioList=DLGCreateRadioList()
RadioList.DLGAddRadioItem("option 1",1)
RadioList.DLGAddRadioItem("option 2",2)
RadioList.DLGAddRadioItem("option 3",3)
DLGitems.DLGAddElement(RadioList)
Return DLGitems
}
MySub(Object self)
{
self.init(self.gen_MySubUI_dlg())
self.Display("MySubUI")
}
~MySub(Object self)
{
Result("Quit" + "\n")
}
}
Class MyMain:UIFrame
{
Object SubDialog
Void CallSubDialog(Object self)
{
Result("\nOpen sub-dialog.")
SubDialog.Pose() // call the local object
self.LookUpElement("Label").DLGTitle("option chosen")
}
Object Init(Object self, Object SDpass)
{
SubDialog = SDpass // Keep the object in a local variabl
TagGroup DLGitems = DLGCreateDialog("Main")
DLGitems.DLGAddElement(DLGCreateLabel("choose option").DLGIdentifier("Label"))
DLGitems.DLGAddElement(DLGCreatePushButton("Options","CallSubDialog"))
Return self.super.Init(DLGitems)
}
}
Object SubDialogOBJ = Alloc(MySub) // Initialize the sub-dialog object in the main script
Object DialogOBJ = Alloc(MyMain).Init(SubDialogOBJ) // Pass on the object into the other
DialogOBJ.Display("Dialog")
Class MySub:UIFrame
{
TagGroup gen_MySubUI_dlg(Object self)
{
TagGroup DLGitems = DLGCreateDialog("Sub")
TagGroup RadioList=DLGCreateRadioList()
RadioList.DLGAddRadioItem("option 1",1)
RadioList.DLGAddRadioItem("option 2",2)
RadioList.DLGAddRadioItem("option 3",3)
DLGitems.DLGAddElement(RadioList)
Return DLGitems
}
MySub(Object self)
{
self.init(self.gen_MySubUI_dlg())
self.Display("MySubUI")
}
~MySub(Object self)
{
Result("Quit" + "\n")
}
}
Class MyMain:UIFrame
{
Object SubDialog
Void CallSubDialog(Object self)
{
Result("\nOpen sub-dialog.")
Alloc(MySub) // call the local object
}
Object Init(Object self)
{ // Keep the object in a local variabl
TagGroup DLGitems = DLGCreateDialog("Main")
DLGitems.DLGAddElement(DLGCreateLabel("choose option").DLGIdentifier("Label"))
DLGitems.DLGAddElement(DLGCreatePushButton("Options","CallSubDialog"))
Return self.super.Init(DLGitems)
}
}
Object DialogOBJ = Alloc(MyMain).Init() // Pass on the object into the other
DialogOBJ.Display("Dialog")
I do not quite understand your question. In your 2nd code you call
self.Displayin the constructor, so naturally the dialog gets immediately displayed?Maybe you need to understand the concept of a
constructormethod better? This method is called (i.e. the code is run) the moment the object is created in memory, i.e. when you callAlloc(mySub)you create the object of class 'mySub' in memory, which invokes its constructor method.I'm adding an example of what you might want to do: Allocate the sub-dialog while the main script is still in scope, but do not display it. Instead, hold it as member variable of the the main dialog and display when the button is pressed (in the "OnButtonPressed" action method).
There are different ways that could be done: