[Gambas-user] re turn value from a form
Benoit Minisini
gambas at ...1...
Sat Jan 10 23:03:25 CET 2009
On mercredi 7 janvier 2009, Doriano Blengino wrote:
> kobolds ha scritto:
> > in order to get return value from a form , I create a variable in the
> > form
> >
> > in ftest
> > public retun_value as boolean =false
> >
> > public sub btnOK_click()
> > return_value = true
> > me.close
> > end
> >
> > public sub btncancel_click()
> > return_value = false
> > me.close
> > end
> >
> > --------------------------------
> > from Fmain
> > public sub btnTest_click()
> > dim m_ftest = new ftest
> > m_ftest.showmodal
> > if m_ftest.return_value = false then
> > ......
> > endif
> > end
> >
> > when I run I get error object not found on "if m_ftest.return_value =
> > false then" . my guess is after the ftest close , the ref memory also
> > gone . this shouldn't be happen like this right ?
>
> You are right - the form (better, the instance of the class) has gone.
> There are three solutions.
>
> 1) Read the documentation. ShowModal() can return a value, which is the
> one passed to FTest.Close().
> It has some limitations (if you close the form using the "X" button,
> this value will be 0, if I well remember).
> This should be the canonical solution.
>
> 2) Don't know if it works. You could make *two* references to ftest
> (ref1=new ftest; ref2=ref1). When the form closes, there is still a
> reference; don't know what precisely do a form when it closes. On other
> platforms, a Close() simply hides the form, so this method works, but
> with gambas Close() normally destroys the form, so who knows what
> happens? This is a dirty solution.
The Persistent property of a form will tell if the Close() method just hides
it, or destroys it.
When a form is destroyed, the associated Gambas object is not necessarily
destroyed (if you have references on it in a variable), but it becomes
invalid. You can't use it anymore!
But if you use static public variables, you will be able to access them, as if
the form object is invalid, the class object of the form that holds the
static variable is usable.
When your form is actually a dialog box, you will use one of them at the same
time. Your form class is a "singleton", i.e. you have only one instance of
them. So using static variables is perfectly logical.
Regards,
--
Benoit Minisini
More information about the User
mailing list