Beim Compilieren gibt es Compilerfehler an der Stelle, an der ich die Sortierung aufrufe:
Code: Alles auswählen
unit1.pas(151,30) Error: Incompatible type for arg no. 1: Got "<procedure variable type of function(Pointer,Pointer):LongInt of object;Register>", expected "<procedure variable type of function(Pointer,Pointer):LongInt;Register>"
(Ich werkel mit Lazarus 0.9.30, FPC 2.4.2. auf einem WinXP SP3)
Hier der Code:
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
FileUtil,
Forms,
Controls,
Graphics,
Dialogs,
StdCtrls,
Grids,
LCLType;
type
TCompareDesc = function (Item1, Item2: Pointer): integer of object;
{ TsdkCell }
TsdkCell = class
Value,
PreviousValue: byte;
Candidates: array[1..9]of byte;
CandList: TList; { Diese Liste will ich u.a. auf- und abwärts sortieren können. Sie enthält Pointer auf die einzelnen Einträge in Candidates. }
private
{ private declarations }
//FCompareDesc: TCompareDesc;
public
{ public declarations }
constructor Create;
destructor Destroy; override;
...
procedure SetCandidate(aCandidate: byte);
function CompareDesc(Item1, Item2: Pointer): integer;
end;
{ TForm1 }
TForm1 = class(TForm)
...
end;
var
Form1: TForm1;
implementation
{ TsdkCell }
constructor TsdkCell.Create;
begin
Value:=0;
PreviousValue:=Value;
CandList:= TList.Create;
InitCandidates;
//CompareDesc:=FCompareDesc;
end;
procedure TsdkCell.SetCandidate(aCandidate: byte);
var
Index: integer = -1;
begin
if aCandidate>0 then
begin
Candidates[aCandidate]:=aCandidate;
Find(aCandidate, Index);
if Index>=0 then
begin
CandList.Add(@Candidates[aCandidate]);
end;
CandList.Sort(@CompareDesc); { Hier bleibt der Compiler mit obiger Fehlermeldung hängen. }
end;
end;
function TsdkCell.CompareDesc(Item1, Item2: Pointer): integer;
begin
Result:=Integer(Item2^)-Integer(Item1^);
end;
Bin dankbar für jeden Tipp!
Aldi