I have an xojo application that incorporates a number of listboxes. One of the listbox objects is named DLBObject. I simply want to add new methods to the DLBObject so that I can then invoke these methods using dot notation. For example DLBObject.DayForward. How do I do that? THANX!!!
2 Answers
Create a new Class, let's name it "MyListBox", and set its Super name to "ListBox".
Add your methods to that class.
Then, in the window, change the Super of each of your listboxes from "ListBox" to "MyListBox" (show the Inspector to see the properties of the listbox controls).
Now these listboxes use the new extended class you create and have those new methods you added.

- 11,045
- 8
- 74
- 149
The answer by Thomas is the usual way of extending the functionality of a built in class, sub-classing is usually what you want to do.
However, sometimes you want to make available functionality to all your different Listboxes and their sub-classes, or even all types of controls or parent classes for the classes you can use (e.g. RectControl
).
For that, you can create Global methods in a Module that have their first parameter as the type of class you want to extend and prefixed with the "Extends
" keyword. For example:
Sub AppendToColumn(Extends sender As Listbox, value As String, column As Integer)
if sender.ListCount > 0 and column > -1 and sender.ColumnCount > column then
for rowIndex As integer = 0 to sender.ListCount - 1
sender.Cell(rowIndex, column) = sender.Cell(rowIndex, column) + value
next
end if
End Sub
You would then be able to use that function on any Listbox...
DLBObject.AppendToColumn(" wibble", 0)
or...
me.AppendToColumn(" wobble", 1)
from within the scope of the Listbox.

- 3,395
- 1
- 25
- 26