Reputation: 8086
type
TMyForm= class(TForm)
sg : TStringGrid;
imgSortIt: TImage;
...
procedure imgSortItClick(Sender: TObject);
private
{ Private declarations }
// sortIt: TFMXObjectSortCompare;
function sortIt(item1, item2: TFmxObject): Integer;
public
{ Public declarations }
end;
var
frm: TMyForm;
implementation
{$R *.fmx}
procedure TMyForm.imgSortItClick(Sender: TObject);
begin
sg.Sort(???);
...
Hi,
I know how to switch rows to manually sort a grid...
But as a TSTringGrid
has a procedure Sort
, I try to use it with my own comparison function with this procedure...
How should I structure the type/function to make it work? Actually, I get:
E2009 Incompatible types: 'regular procedure and method pointer'
sortIt: TFMXObjectSortCompare;
but how to implement the code to sort like I wish?Thanks for your help.
Upvotes: 1
Views: 2186
Reputation: 612993
You are looking at the XE3 documentation, according to which TFmxObjectSortCompare
is declared as:
reference to function(Right, Left: TFmxObject): Integer;
In XE2, unfortunately, TFmxObjectSortCompare
is declared like this:
function(item1, item2: TFmxObject): Integer;
So you will need to supply a regular procedure. That is, sortIt
is not allowed to be a method of a class and must be just a plain old function:
function sortIt(item1, item2: TFmxObject): Integer;
begin
Result := ...
end;
I suspect that this was a design error in the XE2 FMX code. The sort compare function is much more flexible as reference to
, which presumably is why it was changed.
Upvotes: 1