[Gambas-user] How do I override an Array class?

Bruce bbruen at ...2308...
Sun Jun 17 14:38:09 CEST 2012


On Sun, 2012-06-17 at 13:45 +0200, tobi wrote:
> I have done overriding Variant[] successfully (extended it by a specific Sort() method) but it
> caused an interpreter complaint (I do not use the IDE) until (excluding) rev #4715 so it would be
> interesting what message you get and what revision you use... (and maybe what the critical code
> looks like)
> 
> Regards,
> Tobi

> (I do not use the IDE)
Aha! Good point.  
Maybe that would solve my issue.  I have only been trying to do this
within the IDE.  Will try that tomorrow.

> (extended it by a specific Sort() method)
I haven't tried to sort Variants[] yet.  (That is further down the track
in this particular exercise.)

> (and maybe what the critical code
> looks like)
There is no critical code that fails, just achieving the class override
in the IDE so far is the issue.  Currently, I'm just trying to simplify
things like converting a Variant[] containing, say a string and two
strings with integer values in them, like ["Hello","1","24"] to
["Hello",1,24].  Weird? No. The parser code only sees string values and
spends a lot of time (and considerable code) converting a recognised
pattern into a usable pattern example.  What I am trying to achieve is
things in my Variant[] override like adding a Decode method that will
return a converted String[] to a Variant[]:

Public Function Decode(ivar as String[], pattern as Integer[]) as
Variant[]

(simplified and all error checking removed)

  select Case pattern 
...
    case [gb.string, gb.integer, gb.integer]
      return [ivar[0],Val(ivar[1]),val(ivar[2])]
...

End

Why? Because there are at least 20 or 400 or 40 gazillion chunks of code
in the parser classes that do things like this inline. Why? Not because
of a bad design, more because of a lack of design in the first place...
and it just grew.

The time has come to grasp the proverbial bull by his (ahem) and fix it.

back later
Bruce 









More information about the User mailing list