Best method for making a small modification to a gambas builtin class file
Posted
#1
(In Topic #1119)
Regular

To achieve this I have copied the contents of /home/user/gambas-3.18.2/comp/src/gb.gui.base/.src/ListBox/ListBox.class to my project with a new class name RichListBox. I only changed one line of code in "Public Sub GridView_Data" like so:
Code (gambas)
Now I have the desired behaviour. But I was wondering is there a better way to make such a small change to an existing class - one that doesn't involve copy pasting all the code from the original class?
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

p.s. It also depends if you just have a local single project that needs to "add something", overriding the class internally in that project is the simplest (believe me!) way to do it. Otherwise if you need that additional feature then vuott's, somewhat cryptic reference to creating custom components is better.
Posted
Regular

thatbruce said
Somewhere in the help is the description of how to override classes in your application.
Yeas, extend and override sound like something I am after.
I like to use a google search for the gambas wiki with target site specified like this:
Code
class override site:https://gambaswiki.orgThen I came up with this for my RichListBox class:
Code (gambas)
- .Background = Color.SelectedBackground
- .Foreground = Color.SelectedForeground
Unknown symbol '$hView' in class 'Container'
Posted
Regular

With Super.$hView.Data
I doubt that "$hView" is a public attribute of the ListBox. Seek another attribute that provides what yoe need.
Posted
Guru

$hView is Private to ListBox.class so your inheriting class does not see it.
Sometimes the inherited class may have a hidden function that accesses what you want like this..
ListBox does not
but examining the code we see that $hView points to the GridView that is it's Proxy
So we can see that $hView is the first child of the ListBox and also the Proxy so we can access it like this…
Code (gambas)
- ' Gambas class file
- $hView.Data.RichText = $hView.Data.Text ' move Text to RichText
- $hView.Data.Text = ""
Posted
Regular

Good to know. Thank you for this information.BruceSteers said
Inheritance becomes tricky when you want to access internal private data.
Nice work around.BruceSteers said
Code (gambas)
' Gambas class file $hView.Data.RichText = $hView.Data.Text ' move Text to RichText $hView.Data.Text = ""
1 guest and 0 members have just viewed this.


