[Gambas-user] How to extend the String[] class ??

Martín mbelmonte at belmotek.net
Fri Nov 24 16:53:47 CET 2023


El 23/11/23 a las 14:02, Benoît Minisini escribió:
> But you can use normal class name for inheriting "String[]", it should 
> work. 

Yes, It works.

' Gambas class file

Export

Inherits String[]

Property Filled As Boolean
Private bFilled As Boolean

Private Function Filled_Read() As Boolean

   Return bFilled

End

Private Sub Filled_Write(Value As Boolean)

   Dim v As Variant
   Dim s As String
   Dim a As New String[]
   Dim ai As New Integer[]
   Dim i As Integer

   bFilled = Value

   If bFilled Then
         For Each v In Me
           If v <> "" Then
             a.Add(v)
           Endif
         Next
         Me.Clear
         For Each s In a
           Me.Add(s)
         Next
   Endif

End

I don't know the reason why String[] cannot be extended in IDE just like 
the others native clases such String, JSON etc. , if it is on purpose or 
a hangover from the early days of the language, but wouldn't it be 
better that the classes have a name that allows them to be instantiated, 
i.e. without the brackets []?
But surely you will not like this "solution" because it would imply a 
change in the root of gambas3.

Then it is easy, just rename all the classes that are called Something[] 
as SomethingX where X is the dimension of the array (it is Just an idea) 
that is to say:

String[] = String1

String[][] = String2

Integer[] = Integer1

Integer[][] = Integer2

And so on.



More information about the User mailing list