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

Fabien Bodard gambas.fr at gmail.com
Fri Nov 24 17:33:15 CET 2023


In the other hand why are you not using you own derivated type

Just create a class named "String1" or other
With inherit String[]


Use it every where you need

Dim myarray as new string1

Just somme return that need to be passed to a string1 type

For example split()

You can't do split(...). myarrayfunction
You must do
Dim myarray as string1 = split(...)
Myarray.myarrayfuntion

But you lost only 1 line.






Le ven. 24 nov. 2023 à 16:51, Martín <mbelmonte at belmotek.net> a écrit :

> 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.
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20231124/20eb2c10/attachment.htm>


More information about the User mailing list