[Gambas-user] Question about collections and inheritance
Fabien Bodard
gambas.fr at ...626...
Sat Aug 28 23:46:08 CEST 2010
public function _Get(id as string) as style ;-)
Le 28 août 2010 23:36, Benoît Minisini <gambas at ...1...> a écrit :
>> Hi all.
>>
>> I'm trying to code a very basic Xml Excel Generator, and I'm workin with
>> a collection. This is my code:
>>
>> ' Gambas class file
>>
>> Inherits Collection
>>
>> Public Function Add($ID As String) As Style
>>
>> Dim $style As New Style($ID)
>>
>> Super.Add($style, $ID)
>>
>> Return $style
>>
>> End
>>
>> Public Function _GetXml() As String
>>
>> Dim $style As Style
>> Dim $text As String = "\t<s:Styles>\n"
>>
>> For Each $style In Me
>> $text &= $style._GetXml() & "\n"
>> Next
>>
>> $text &= "\t</s:Styles>"
>> Return $text
>>
>> End
>>
>> Style is another class I have. My class inherits the Collection class
>> and I override the Add function. All of this works fine, my question is
>> about another Collection functionality:
>>
>> With a normal Collection we can do something like this:
>>
>> Dim $col As Collection
>> $col.Add("My value", "key")
>> Print *$col["key"]*
>>
>> I can access to my item whit his "key". How can I override this
>> functionality in my class, because Gambas return me a Variant data type
>> element and I want to return my own data type, my Style class.
>>
>> Thanks.
>>
>> P.S. Sorry my english, I trying to learn it but I'm still newbie
>>
>
> You have to override the _get() method. Something like that I presume:
>
> Public sub _get(Id As String) As Style
>
> Return Super[Id]
>
> End
>
> Regards,
>
> --
> Benoît Minisini
>
> ------------------------------------------------------------------------------
> Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
> Be part of this innovative community and reach millions of netbook users
> worldwide. Take advantage of special opportunities to increase revenue and
> speed time-to-market. Join now, and jumpstart your future.
> http://p.sf.net/sfu/intel-atom-d2d
> _______________________________________________
> 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