Sort Tlist lazarus / 13-General ---------------------------------------------------------------------- arneolav · 2009-10-27 15:31 Hi! I have some pointer trouble in TList sorting in the following example code, Error is marked in function CompareBinSRecs. Compiler mess: unit1.pas(47,14) Error: Illegal qualifier unit1.pas(47,14) Hint: may be pointer dereference is missing unit1.pas(47,14) Fatal: Syntax error, "THEN" expected but "identifier TWORD" found Any ideas? Thanx in advance. Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   StdCtrls, Math; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     { public declarations } end; type   TBinSRec = record   tWord  : String;   tNum   : Integer end; pBinSRec = ^TBinSRec; var ptRec: pBinSRec; var BinSRec0  : TList; var   Form1: TForm1; implementation function  CompareBinSRecs (p1, p2: pointer): integer; var r1: pBinSRec absolute p1;     r2: pBinSRec absolute p2; begin   If      r1.tWord < r2.tWord then Result := -1     // ERROR   else if r1.tWord > r2.tWord then Result := +1   else                             Result := 0; end; Procedure BuildTList; var i, x : Integer; begin   x:=9;   BinSRec0 := TList.Create;   BinSRec0.Capacity := x;   while  i <  x do   begin         New(ptRec);         BinSRec0.Add(ptRec);      {save for sort}         ptRec.tWord:= 'x';         ptRec.tNum := x;     inc(i);   end; {while i < x}   BinSRec0.Pack; end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   BuildTList;   BinSRec0.Sort(CompareBinSRecs); end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- eny · 2009-10-27 15:43 Better try: r1^.tWord and r2^.tWord. And also: BinSRec0.Sort(@CompareBinSRecs); (note the at-symbol). Or: Code: [Select]function  CompareBinSRecs (p1, p2: pointer): integer; begin   result := AnsiCompareStr(pBinsRec(p1)^.tWord, pBinsRec(p2)^.tWord) end; ---------------------------------------------------------------------- Vincent Snijders · 2009-10-27 15:52 Or if you prefer to use the automatic dereferencing as in Delphi, use {$mode delphi}. ---------------------------------------------------------------------- arneolav · 2009-10-27 15:59 Thanx, Then it compiles fine. The code is from a Delpi true_time translating app. Seems I have a job to do as the Delphi application is bulid on heavy use of Tlist and pointers with this same syntax.