return value from a form

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

return value from a form

kobolds
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 ?

Reply | Threaded
Open this post in threaded view
|

Re: re turn value from a form

Doriano Blengino
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.

3) Don't know if it works either. You could use Visible=False in FTest,
instead of closing it. Again, on other platforms this works. The form is
not destroyed and, if gambas is smart enough, it understands that a
hidden form can not be modal.

Ciao,

--
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: re turn value from a form

Rolf-Werner Eilert
In reply to this post by kobolds
kobolds schrieb:

> 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 ?
>
>

Why don't you do it just the other way round: Make a public variable in
FMain, write the value into it from ftest before it's closed, so the
value will still be in the variable within FMain after closing. Or did I
get you wrong somehow?

This way:



' in ftest:

  public sub btnOK_click()
   FMain.return_value = true
   me.close
  end

  public sub btncancel_click()
    FMain.return_value = false
    me.close
  end
 >
 > --------------------------------
' in FMain
public retun_value as boolean =false

  public sub btnTest_click()
   dim m_ftest = new ftest
   m_ftest.showmodal
   if return_value = false then
      ......
   endif
  end


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|

Re: re turn value from a form

Benoît Minisini
In reply to this post by Doriano Blengino
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user