[Gambas-user] Gambas bug?
Emil Lenngren
emil.lenngren at ...626...
Fri Feb 10 23:57:07 CET 2012
So what you want is to extend the array class with some extra methods?
Just use
Inherits Person[]
in the PersonList class ;)
/Emil
2012/2/10 Fabián Flores Vadell <fabianfloresvadell at ...626...>
> 2012/2/10 Emil Lenngren <emil.lenngren at ...626...>
>
> > Can you give some examples how you mean?
> > What do you need wrappers for?
> > I don't think I understand fully what you mean, but it seems interesting
> :)
> >
> > /Emil
> >
>
> I would like to show you an example, but I can't.
> If I did, I would have to kill you. :P
>
>
>
>
>
> There is a foolish example:
>
>
> '*****************
> ' Class Person
> '*****************
>
> $FirstName As String
> $LastName As String
>
> Property Read FirstName As String
> Property Read LastName As String
>
> Public Sub _new(fname As String, lname As String)
> $FirstName = fname
> $LastName = lname
> End
>
> Private Function FirstName_Read() As String
> Return $FirstName
> End
>
> Private Function LastName_Read() As String
> Return $LastName
> End
>
> '*********************
> ' PeopleList class
> '*********************
>
> 'aPeople is a collaborator from which I want to expose some methods (by the
> PeopleList message protocol)
>
> Private $aPeople As New Person[]
>
> 'The Call method implement the "instrospective call" "pattern" (okay, I
> just made it up... but it works!)
>
> Public Sub Call(aMethodName As String, Optional arguments As Array = Null)
> As Variant
> Dim result As Variant
>
> If Not [Add, Clear, Count, Insert, {Max}].Exist(aMethodName) Then Return
>
> Object.Call($aPeople, aMethodName, arguments)
>
> Catch
> Return Object.GetProperty($aPeople, aMethodName)
> End
>
> 'I want avoid code like this:
>
> ' Public Sub Add(aPerson As Person)
> ' $aPeople.Add(aPerson)
> ' End
> '
> ' Public Sub Insert(arrayPerson As Person[])
> ' $aPeople.Insert(arrayPerson)
> ' End
> '
> ' Public Sub Clear()
> ' $aPeople.Clear
> ' End
> '
> ' Property Read Max
> '
> ' Private Function Max_Read()
> ' $aPeople.Max
> ' End
> '
> 'and so on
>
> 'More methods for PeopleList:
>
> Public Sub PrintList()
> Dim aPerson As Person
>
> For Each aPerson In $aPeople
> Print aPerson.FirstName & ", " & aPerson.LastName
> Next
> End
>
> '**************
> ' Test Class
> '**************
>
> Static Public Sub Main()
> Dim aPeopleList As New PeopleList
> Dim MaxItems As Integer
> Dim Person1, Person2, Person3, Person4 As Person
> Dim Person5, Person6, Person7, Person8 As Person
>
> Person1 = New Person("Carlos", "Delfino")
> Person2 = New Person("Lionel", "Messi")
> Person3 = New Person("Luis", "Scola")
> Person4 = New Person("Emmanuel", "Ginóbili")
>
> 'Here are introspective calls:
> With aPeopleList
> 'Very ugly sintactically, but that is all we got
> .Call(.Insert, [[Person1, Person2, Person3]])
> .Call(.Add, [Person4])
> End With
>
> Person5 = New Person("Jhon", "Doe")
> Person6 = New Person("Jane", "Doe")
> Person7 = New Person("Nobody", "Gates")
> Person8 = New Person("Genius", "Minisini")
>
> 'Here are introspective calls:
> With aPeopleList
> .Call(.Insert, [[Person5, Person6, Person7], .Call(.Max)])
> .Call(.Add, [Person8])
> Print .Call(.Count)
> End With
>
> aPeopleList.PrintList
> End
>
>
>
> > --
> >
> Fabián Flores Vadell
> www.comoprogramarcongambas.blogspot.com
> www.speedbooksargentina.blogspot.com
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list