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

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -