I'm having a slight problem with using custom functions with SORTARRAY. The example (sorting primitive types) works, but not types are used.
This is the error:
QuoteIn file included from C:\Users\James\AppData\Local\Temp\glbasic\gpc_tempg.cpp:2:
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: `Anything' was not declared in this scope
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: `Anything' was not declared in this scope
C:\Users\James\AppData\Local\Temp\glbasic\gpc_temp.h:8: error: initializer expression list treated as compound expression
As gpc_temp.h is included in the different source files, this error is repeated a few times, but its complaining about the line of 'gpc_temp.h' that declares the sort function:
DGInt SortFunc(Anything A, Anything B);
Demo snippet:
TYPE MyType
var%
ENDTYPE
LOCAL Array[] AS MyType
SORTARRAY Array[], ADDRESSOF(SortFunc)
FUNCTION SortFunc: BYREF A AS MyType, BYREF B AS MyType
IF A.var > B.var THEN RETURN 1
IF A.var < B.var THEN RETURN -1
RETURN 0
ENDFUNCTION
Have you tried (see below) - That's all I do and have no problems with compilation.
FUNCTION SortFunc: A AS MyType, B AS MyType
IF A.var > B.var THEN RETURN 1
IF A.var < B.var THEN RETURN -1
RETURN 0
ENDFUNCTION
Byref isn't used when passing structures.
Ahhh - knew I had something wrong. Thanks!
and types are always passed byref.