[Gambas-user] Direct assignment to arrays of inherited classes does not work

Fabien Bodard gambas.fr at ...626...
Mon Sep 22 18:09:08 CEST 2014


strange...

has we can say Control = TextBox ... no ?


2014-09-22 11:03 GMT+02:00 Julio Sanchez <jusabejusabe at ...626...>:
> Thanks Tobi, I'll try :)
>
> Regards,
>
> Julio
>
> 2014-09-22 10:46 GMT+02:00 Tobias Boege <taboege at ...626...>:
>
>> On Mon, 22 Sep 2014, Julio Sanchez wrote:
>> > Direct assignment to arrays of inherited classes does not work
>> >
>> > We have a class that inherits from the integer class [], we call
>> > SuperInteger, this is your code:
>> > Inherits Integer []
>> >
>> > Public function  higher() as integer
>> > dim itemt as integer
>> > dim ihigher as integer
>> >
>> > for each element in me
>> > ihigher = max (ihigher, item)
>> > next
>> >
>> > return ihigher
>> >
>> > end
>> >
>> >
>> > When I make an instance of the new :
>> >
>> > dim test as new SuperInteger
>> >
>> >
>> > It does not work this assignment:
>> > test = [86, 16, 212, 1, 43, 18]
>> >
>> > gambas3 says it's not the same type.
>> > Should I working? Right?
>> >
>>
>> No, because it is not the same type :-)
>>
>> Even if B inherits A, it can be very difficult to make sense of an
>> assignment myB = myA because myB could reference _lots_ of other
>> information (which is not in the class A). What should happen to this
>> information in the assignment? You simply can't convert myA to the B
>> class.
>>
>> The clean solution would be to define a static B.FromA() method which
>> takes an A object and returns a new B object which contains that A
>> object and initialises all other information appropriately.
>>
>> So, you would implement
>>
>>   Static Public Function FromArray(aArray As Integer[]) As SuperInteger
>>
>> or something along these lines in SuperInteger. For a more concise
>> syntax, you may also use the _call() special method. Then you can do
>>
>>   myB = SuperInteger([1, 2, 3, 4])
>>
>> Regards,
>> Tobi
>>
>> --
>> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>>
>>
>> ------------------------------------------------------------------------------
>> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
>> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
>> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
>> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Fabien Bodard




More information about the User mailing list