[Gambas-user] Custom Control
Benoît Minisini
gambas at ...1...
Sun Nov 29 21:59:27 CET 2009
> Benoît Minisini wrote:
> > In Gambas 3, the /control directory must be put inside the "Project"
> > section.
>
> Okay, that worked. I was using the control directory automatically
> created when I first created the project. Thanks.
>
> > Please provide the details of what you have done, and maybe I will tell
> > you.
>
> I'm referring to code used when programming the component itself.
>
> For example, in the component code:
>
> Public Sub _new(lVal1 As Long, lVal2 As Long, Optional lVal3 As Long)
>
> If I make the component and try to use it in a project, I have to also
> pass the parent container name. So, if I use:
>
> oVar = New ComponentName(lVal1, lVal2, lVal3, FMain)
>
> It works fine. But if I try to leave out the *optional* argument:
>
> oVar = New ComponentName(lVal1, lVal2, FMain)
>
> I will get "Not enough arguments" from the IDE. If I try:
>
> oVar = New ComponentName(lVal1, lVal2, , FMain)
>
> I will get "Unexpected Comma" from the IDE. And, of course, if I pass
> NUll as the optional argument, it's the incorrect data type for the
> argument. I understand why I'm getting the messages I'm getting. I'm
> just asking is there any way to use an *optional* argument to the _new
> sub of a component.
>
> This isn't something critical. This is just a personal project I chose
> to do as an exercise, to get familiar with Gambas. I always do stuff
> like this whenever I'm learning a new language or (in this case) IDE, etc.
>
You get a point there: optional arguments cannot really be used in
constructors, unless you do not use inheritance. Because the rule is that if
an argument is optional, all following arguments are. Which is a contradiction
with the way arguments are used.
Maybe I should change the way arguments are consumed by inherited
constructors. I mean not inverting them, i.e. inverting them on the stack, so
that you write New MyControl(FMain, lVal1, lVal2...). But this will uses some
CPU.
I must think about that...
--
Benoît Minisini
More information about the User
mailing list