I am trying to implement an InputBox function seen in other OO language like VB and Delphi.
Code: Select all
int num=InputBox();
InputBox function will open a pop up window,one can enter an integer in the window and then press OK button.After the popup windows closes,the main procedure will receive and make use of this integer value.
To make it,It is not difficult actually to me.But I encountered a problem on when the popup windows should be destroyed .
My first trial is to place the Destroy(0) in the int InputBox() function body after popup.Modal().But this does not work properly.The popup windows never close.
Then I place the Destroy(0) in the OK button's left click event handler right after the int variable 'number' has been modified in the popup windows class.It works,but I am confused now.
Code: Select all
import "ecere"
int InputBox()
{
int num;
FormInteger form{};
form.Modal();
num=form.number;
//form.Destroy(0);//first trial
return num;
}
class FormInteger : Window
{
caption = "整数:";
background = activeBorder;
borderStyle = fixed;
size = { 368, 148 };
anchor = { horz = -107, vert = -153 };
public:
int number;
property int number
{
set { number=value;}
get {return number;}
}
Button btnOK
{
this, caption = "OK", altO, isDefault = true, size = { 74, 21 }, position = { 256, 80 };
bool NotifyClicked(Button button, int x, int y, Modifiers mods)
{
number=atoi(txtNumber.contents);
//Destroy(0); //second trial
return true;
}
};
Label label1 { this, caption = "请输入整数:", size = { 140, 13 }, position = { 16, 8 } };
EditBox txtNumber { this, size = { 326, 19 }, position = { 16, 32 } };
}
1.First trial:in the InputBox() body,the popup window created,opened in modal,read the property number's value and save to variable num,then it is destoryed.I think this is the proper sequence but it turns out it is totally wrong.
2.Second trial:in the button click event body,after the property number was set ,window was destroyed immediately.Now in the InputBox() body,the popup window created,opened in modal,when OK button was pressed,the window destoryed immediately,so how can I read and save the property number's value?I have though this for several times and believe this does not make sence,but it does actually.
This is why I am confused.Hope I described the question clear.
Thanks for the help.
Regards,
Sam