[Gambas-user] array of object is SO needed
Rolf-Werner Eilert
rwe-sse at osnanet.de
Tue Mar 31 14:00:34 CEST 2020
Hi Roberto,
there are arrays of objects in Gambas, and I have been using them for
quite some time. There is especially one project where I used them very
similarly: for labels, textboxes and comboboxes in a dynamical mask.
As an example, at the beginning of the class file:
Private mLbl As New Object[]
This is a small excerpt where a new label is made and set to its position:
Case "LABEL"
Inc lblNr
mLbl.Resize(lblNr + 1)
mLbl[lblNr] = New Label(Maske) As "MaskeLabel"
mLbl[lblNr].X = Val(wert[2])
mLbl[lblNr].Y = Val(wert[3]) + 5 'Gambas 3 Ausgleich nötig
mLbl[lblNr].Text = wert[4]
'5 und 6 noch für den Font
mLbl[lblNr].Width = mLbl[lblNr].Font.TextWidth(mLbl[lblNr].Text)
mLbl[lblNr].Height = mLbl[lblNr].Font.TextHeight(mLbl[lblNr].Text)
You have to take care to delete the objects backwards (for... step -1):
For i = mLbl.Count - 1 To 0 Step -1
mLbl[i].Delete
Next
mLbl.Clear
As far as I know, you could even define Arrays of Arrays, for your
multilayer matrix for instance, to simulate the layers, but I never
needed that.
Or did I get you completely wrong here?
Regards
Rolf
Am 31.03.2020 um 12:16 schrieb roberto:
> hi.
>
> i am doing a "sudoku" game.
>
> i have a matrix of 81 labels, from "label1" to "label81" as containers
> of the numbers (to show them to user)
>
> i have matrix to container of number (to "elaborate" them).
>
> To fill the textlabels i have to do
>
>
> if matrix[1] <> 0 then label1.text=matrix[1]
>
> if matrix[2] <> 0 then label2.text=matrix[2]
>
> ...
>
> if matrix[81] <> 0 then label81.text=matrix[81]
>
>
> also to clean or assign different background color, i have to write 81
> times the same command on different labels.
>
> it will be HUGE better to have array of objects to allow some the
> follow:
>
>
> for n = 1 to 81
>
> if matrix[n] <> 0 then label[n].text = matrix[n]
>
> next
>
> At my eyes, absence of object arrays is the worsest weakness of gambas.
>
>
> PS: in past i did bigger programs with hundreds of labels and all of
> them must be worked one by one, it was a mess (doing cut and past and
> renumbering, it is so common to do a mistake).
>
> Getting older, i became less used to face this weakness.
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
>
More information about the User
mailing list