Este tema va de aclarar el funcionamiento de gambas a la hora de extender una clase.
Si tomamos por ejemplo la clase nativa String
Vemos que existen una serie de métodos.
Luego si se desea crear una clase String extendida dentro de un proyecto gambas basta con colocar Inherits String al comienzo de la clase que tendrá los métodos "nuevos"
' gambas class file
'' This class extends the standard String class in gambas
Export
Create Static
Inherits String
'' This function counts how much times some string apear in other
Public Function Count(sWhere As String, sWhich As String) As Integer
Dim i As Integer = 1
Dim Cursor As Integer
Dim Counter As Integer
Repeat
Cursor = InStr(sWhere, sWhich, i)
If Cursor > 0 Then
Inc Counter
i = Cursor + String.Len(sWhich)
Endif
Until InStr(sWhere, sWhich, i) = 0 Or i > String.Len(sWhere)
Return Counter
End
'' This class extends the standard String class in gambas
Export
Create Static
Inherits String
'' This function counts how much times some string apear in other
Public Function Count(sWhere As String, sWhich As String) As Integer
Dim i As Integer = 1
Dim Cursor As Integer
Dim Counter As Integer
Repeat
Cursor = InStr(sWhere, sWhich, i)
If Cursor > 0 Then
Inc Counter
i = Cursor + String.Len(sWhich)
Endif
Until InStr(sWhere, sWhich, i) = 0 Or i > String.Len(sWhere)
Return Counter
End
Hasta aquí todo fenómeno, pero....
Que es lo que sucede si activamos el componente gb.util.
Este componente tiene una clase llamada String pero en su interior no existe la palabra clave Inherits sin embargo extiende la clase original String de gb
¿Como lo hace?
Es mas ahora en el ejemplo anterior de extensión de clase aparecen los métodos extendidos por gb.util.
¿Como funciona esto?
Saludos.