[Gambas-user] Inherit Button, looks bad in the IDE?

Bruce Steers bsteers4 at gmail.com
Wed Feb 17 18:22:39 CET 2021


On Wed, 17 Feb 2021 at 16:07, Tobias Boege <tobs at taboege.de> wrote:

> On Wed, 17 Feb 2021, Bruce Steers wrote:
> > On Wed, 17 Feb 2021 at 13:57, Tobias Boege <tobs at taboege.de> wrote:
> >
> > > On Wed, 17 Feb 2021, Bruce Steers wrote:
> > > > --------------------------
> > > > ' Gambas class file
> > > >
> > > > Export
> > > > Inherits Button
> > > >
> > > > Public Const _Properties As String = "*,Delay=200"
> > > > Public Const _Similar As String = "Button"
> > > >
> > > > '' Get or set Time between flash on/off in ms , default 500
> > > > Property Delay As Integer
> > > > Private $Delay As Integer
> > > > '' Get or set default Time between flash on/off in ms , default 500
> > > > Static Public Default_Delay As Integer = 500
> >
> > i have just recently discovered the power of using Inherit on controls
> in a
> > class and getting into customizing them.
> > Loving it, so far all i have is a flashy colour button and a GridView
> that
> > has built in Sort and MoveRowUp and MoverowDown functions but feeling a
> new
> > area of an awesomely handy library of custom controls ready for import
> into
> > my projects in the making..
> > :)
>
> In addition to what Fabien said, let me give you two pieces of information
> that may be useful to you in the future:
>
> (1) Inheritance sounds fine for the kind of modifications you describe.
> In the Gambas source code, another pattern that occurs, in my experience,
> more often is encapsulation instead of inheritance. When you want to
> modify an already existing control X (modify, extend or even constrain
> aspects of its behavior instead of just adding new methods to it), it is
> more common to write a class Y which Inherits UserControl and creates an
> instance of X *on itself*. This way, you can build a completely new
> interface around the X object. See the SpinBox or _TreeView classes in
> gb.gui.base for one of many examples.
>

Good info , cheers :)
I am able to do more than just add new methods with Inheritance, I find it
pretty manageable so far Using Super and Raise.
I found i could snatch any event with its _Raise name like..

Public Sub _RaiseClick() ' grab the event in the custom class
' do my bits
Raise Click  ' raise the event on the parent class
End
that was quite the revelation for me
And some methods were equally simple to intercept using Super
Public Sub Run(sArgs As String[])
' do my bits
Super.Run(sArgs)  ' run the inherited classes method
End

I think i'm a way off building new controls from scratch,
for starters I just can't think of anything i need (and i have tried)
beyond slight mods to existing controls,


(2) The greatest thing ever in Gambas is making new "compound controls",
> i.e. widgets composed of already existing controls (labels, buttons,
> textareas) which are functioning as one unit. Turning them into a new
> control class lets you drop many instances of the same GUI logic into
> your forms easily, or create new instances at runtime. What is so great
> about this is that you can design these compounds in the IDE form designer,
> giving you a FZ.form and FZ.class, which you can then wrap under a neat
> and tidy API in Z.class using the encapsulation (1). This works because
> you can embed a Form in another container (which in turn lives on some
> other Form) like any other control. Notable examples include the
> DataBrowser
> in gb.db.form or the FileProperties widget in gb.form.


ahh yes i think used a similar thing when i modified the Message.class
Have just been browsing around the FileProperties code.  lots to take in.

Thank you for the info, much appreciated :)
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210217/c0108a6e/attachment.htm>


More information about the User mailing list