[Gambas-user] Write protected array

Tobias Boege taboege at gmail.com
Tue Dec 3 21:59:09 CET 2019


On Tue, 03 Dec 2019, Dag Jarle Nerland Johansen - Gambas wrote:
> I still can't really make it, so here some source sniplets, where the error
> occurs.
> Gambas Version 3.14.2
> 
> Declaration:
> Public sortname_LOGO[9, 2] As String
> If I try  Public sortname_LOGO[9, 2] As New String
> it  makes another error here (I only have that in German: "NEW und
> eingebetteter array kann nicht kombiniert werden", I assume "NEW and
> embedded array can't be combined")
> 

Your translation is correct. It is the same error that I linked to earlier
and that Johny also recalled. There is a bug in Gambas 3.14.X where the
kind of array you use (embedded arrays) are read-only by default. This has
already been fixed on master but there was no 3.14.3 release yet.

You can work around this bug right now by turning your embedded array
declaration

  Public sortname_LOGO[9, 2] As String

into a real array

  Public sortname_LOGO As New String[9, 2]

And why are you using embedded arrays in the first place? Normal arrays
have many advantages over embedded arrays, such as:

  - they can grow and shrink dynamically,
  - their lifetime is not bound to the containing object,
  - they can be local variables.

The only virtue of embedded arrays is that they are placed compactly
inside the containing object, making them suitable to interact with
native libraries. If you are not doing that, embedded arrays should
be avoided. There is no reason to use them. Although this advice has
nothing to do with this particular bug here.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list