In Visual Basic.Net, A combobox class has an Items property. And it is an indexed property. We can get the items by passing an index as parameter. On the same time, this Items property has some fields and methods like "Add", "Count", "Clear" etc.
My question is, how to do it in FreeBasic ?. I have a combobox type and it contains an Items type. So members like Add, Clear are working very well. I can use the dot notation like this --> "ComboBox.Items.Add("Item1").
But when it comes to an indexed property, compiler gives error messages . And here is the model i am working now. It is not the actual code. But if this prototype worked, i can adapt this into my code.
Code: Select all
Type ItemsClass Extends Object
sList(Any) As String
Declare Property Count() As Integer
Declare Sub Add(Byval Item As String)
Declare Sub Clear()
Declare Sub RemoveAt(Byval Index As Integer)
Declare Sub Insert(Byval Item As String, Byval Index As Integer)
End Type
Property ItemsClass.Count() As Integer
Return Ubound(sList)
End Property
Sub ItemsClass.Add(Byval Item As String)
ArrayAdd(sList, Item) ' ArrayAdd is a simple macro. It just redim and put things into array.
End Sub
Sub ItemsClass.Clear()
Erase sList
End Sub
Type ComboBox
Items As ItemsClass
Declare Property Items(Byval Index As Integer) As String
End Type
Property ComboBox.Items(Byval Index As Integer) As String
Return This.Items.sList(sInd)
End Property
Dim cmb As ComboBox
cmb.Items.Add("Sample val1")
cmb.Items.Add("Second Val")
Print cmb.Items(1)
Sleep
End
1. Property declaration of Items in Combobox - Duplication definition. - (Do i need an Overload clause ?)
I think i am confusing compiler with giving same names for a property and a member type.