Author Topic: How do I declare & use array properties in a class?  (Read 2072 times)

SteveDee

  • Newbie
  • *
  • Posts: 33
How do I declare & use array properties in a class?
« on: December 07, 2009, 06:40:44 AM »
I know I'm still locked into my old VB.Classic mind set, but how should you code for array properties in a class?

In VB I would do something like this:-

Code: [Select]
Dim mstrContactName(100)as string

Public Property Get strContactName(ByVal lngIndex As Long) As String

    strContactName = mstrContactName(lngIndex)

End Property

Private Property Let strContactName(ByVal lngIndex As Long, ByVal strNew As String)

    mstrContactName(lngIndex) = strNew

End Property

But in Gambas you can't pass variables to a Property. So I have to result to using a method like this:-

Code: [Select]
PUBLIC FUNCTION GetContactName(lngIndex AS Long) AS String
 
  RETURN strContact[lngIndex]
 
END

PUBLIC FUNCTION LetContactName(lngIndex AS Long, strNew as String) AS String
 
  strContact[lngIndex] = strNew
 
END

So my question: Is there a better way?

Linux Basic

How do I declare & use array properties in a class?
« on: December 07, 2009, 06:40:44 AM »

enricopallawitschini

  • Newbie
  • *
  • Posts: 5
Re: How do I declare & use array properties in a class?
« Reply #1 on: February 17, 2010, 01:40:45 PM »
Just declare Property as String[]!?

Like:

Property Something as String[]

Private $Something as String[]
PUBLIC FUNCTION Something_Read() AS String[]
 
  RETURN $Something
 
END

PUBLIC SUB Something_Write(Value as String[])
 
  $Something=Value = strNew
 
END


And from Outside just use it like an array(which it is).

MyClass.Something.Add(Value,Index)
MyString=MyClass.Something[index]