[Gambas-user] Sort an array of Objects[] of different Class
martin p cristia
tercoide at hotmail.com
Wed Apr 22 12:49:52 CEST 2020
I doing some GambasCAD program, soon to be in the Farm. The compare
method is at the herited class:
' Gambas class file
Inherits ClsElementoBase ' handles
Clicks and common entity vars
Public Const Genero As String = "Tabique" ' who am I
Public Const DrawingOrder As Integer = 20 ' <-------I SORT THIS : 1
is drawn first
Public Sub _new(x1 As Float, z1 As Float, x2 As Float, z2 As Float,
nivel As Float)
Me.P.Add(puntos.Add(X1, Z1, nivel))
End
Public Function _compare(entities As Object) As Integer
' all entities must have a var called DrawingOrder!
Return Sgn(Me.DrawingOrder - entities.DrawingOrder)
End
What you've suggested works perfectly.
> I don't know what you are going to do with the code, but keep in mind that
> if the object array will get objects, which does not inherit the compare
> method, then you will get silent sorting errors.
> So, either keep the variable used in the comparison in the base class or
> build guard for the object array. Otherwise you will end up with troubles.
>
> Jussi
>
>
--
Saludos
Ing. Martin P Cristia
More information about the User
mailing list