type TBat = record v1: Integer; v2: Integer; v3: Integer; end; PBat = ^TBat;
function SortValue(p1,p2: PBat): Integer; begin result:=CompareValue(p2.v1,p1.v1); if result = 0 then result:=CompareValue(p2.v2,p1.v2); if result = 0 then result:=CompareValue(p2.v3,p1.v3); end;
procedure TForm1.FormClick(Sender: TObject); var i,j: Integer; list: TList; bat: PBat; begin list:=TList.Create; try randomize; for i:=0 to 2 do for j:=0 to 3 do begin new(bat); bat.v1:=i*10; bat.v2:=(j div 2)*20; bat.v3:=random(20); list.Add(bat); end; list.Sort(@SortValue); self.Repaint; for i:=0 to list.Count-1 do begin bat:=list[i]; canvas.TextOut(20, 20*(i+1), inttostr(bat.v1)); canvas.TextOut(50, 20*(i+1), inttostr(bat.v2)); canvas.TextOut(80, 20*(i+1), inttostr(bat.v3)); end; finally for i:=0 to list.Count-1 do dispose(list[i]); list.Free; end; end;