[Gambas-user] Using qsort with Objects

tobi tobiasboege01 at ...1601...
Sun Apr 29 12:47:45 CEST 2012


Hi,

I want to sort an Array of Arrays as Variant[][] that may contain different datatypes in each member
of an array but the arrays are all homogenous (think of a Database, it's not the actual subject but
the same idea). That's what I thought of:

- Write a class that Inherits Variant[] (that will act as the Array containing Variant[], so I could
  also Inherits Object[]?)
- Create a Sort() method for that class that takes an integer N for the member to sort by
  (Variant[][N]) (When Inherits Object[], I get error messages on incorrectly overriding
  Object[].Sort(). The parameter?)
- Call qsort(Super.Data, Super.Count, SizeOf(gb.Pointer), MyCompare) -- _Right?_
- MyCompare consequently takes two Pointers. How may I treat them as being references to Variant[]?
  Any casts possible? After that, it would be easy to use TypeOf(Variant[][N]) and call a
  datatype-specific routine to compare the two values.
  I tried to Private Sub MyCompare(V1 As Variant[], V2 As Variant[]) and got a Segfault after one
  line of wrong results when, in MyCompare, Print V1[0], V1[1] which are valid.

Regards,
Tobi




More information about the User mailing list