sorting - Getting error with generic sort in Delphi Xe2 -
i hope can see might wrong here. in xe2 have generic tobjectlist want sort. have tobjectlist sorting in different place, modelled new code on old. looks correct: compareposcontrol non-oops function; rpt nested method of form, tposctrl simple class.
function compareposcontrol(l, r: tposctrl): integer; begin result := l.sortnum - r.sortnum; end; procedure rpt(rparent: twincontrol); begin posctrls := tobjectlist<tposctrl>.create; try addposctrls(rparent); posctrls.sort(tcomparer<tposctrl>.construct(compareposcontrol)); but keep getting error:
[dcc error] rputils.pas(1552): e2010 incompatible types: 'system.generics.defaults.tcomparison' , 'procedure'
any ideas?
tia
mark
change function match prototype (add const modifier):
function compareposcontrol(const l, r: tposctrl): integer; you may use anonymous function:
posctrls.sort(tcomparer<tposctrl>.construct( function (const l, r: tposctrl): integer; begin result := l.sortnum - r.sortnum; end; ));
Comments
Post a Comment