[Gambas-user] Bug in constructor?

Benoit Minisini gambas at ...2...
Mon Nov 10 15:21:13 CET 2003


Le Lundi 10 Novembre 2003 19:06, danielcampos at ...282... a écrit :
> Hi, Benoît (and company)!
>
>  I was trying to add an optional parameter for 'Socket' constructor, so
> I did it in that way:
>
> _new method:
>
> BEGIN_METHOD(CSOCKET_new,GB_STRING sPath;)
>
>   /* some stuff */
>
>   if (STRING(sPath))
>   {
>   	printf("sPath! --> %s\n",STRING(sPath));
>   }
>
> END_METHOD
>
> And in method definition:
>
> ...
> GB_METHOD("_new", NULL, CSOCKET_new, "[(sPath)s]"),
> ...
>
>
>  Well, I created a little test program :
>
> Private MySock As Socket
> ....
> Public Sub Button1_Click()
>
> 	MySock=New Socket("teststring") As "MySock"
>
> End Sub
>
> Well, after executing it, OK, it appears "teststring" at console (see _new
> method), but then I changed it to see if it really was an optional
> parameter:
>
> 	MySock=New Socket As "MySock"
>
> To my surprise it appeared it console "MySock", that is, the event handler
> was passed like a parameter to the constructor!
>
> I also tried MySock=New Socket() As "MySock" but It didn't work
> at all (Syntax error)
>
> ...
>
> Regards,
>
> Daniel Campos
>
>

Hi, Daniel

This mail should go on the devel mailing-list !

You must test optional argument with the MISSING macro.

BEGIN_METHOD(CSOCKET_new,GB_STRING sPath;)

   /* some stuff */

  if (!MISSING(sPath))
  {
    if (STRING(sPath))
    {
    	printf("sPath! --> %s\n",STRING(sPath));
    }
  }

END_METHOD

Without this test, you saw the "event name" of the object, because it is 
pushed on the interpreter stack just after method arguments !

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...





More information about the User mailing list