[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gambas-user
Subject:    Re: [Gambas-user] re turn value from a form
From:       Benoit Minisini <gambas () users ! sourceforge ! net>
Date:       2009-01-10 22:03:25
Message-ID: 200901102303.25479.gambas () users ! sourceforge ! net
[Download RAW message or body]

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

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic