TList类中有一个Sort方法,但我不知道怎么用,请高手指教!!

解决方案 »

  1.   

    type
      PRecord = ^TMyRec;
      TMyRec = record
        s: string[8];
        i: integer;
        d: double;
    end;function CompareInt(Item1, Item2: PRecord): Integer; //排序
    begin
      Result := CompareValue(Item1.i, Item2.i);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var MyList: TList;
        PR: PRecord;
    begin
      MyList := TList.Create;
      try
        New(PR);
        PR.s := '10000001';
        PR.i := 1001;
        PR.d := 0.1;
        MyList.Add(PR);
        {...}
        MyList.Sort(@CompareInt); //Integer類Sort
      finally
        MyList.Free;
      end;
    end;注:你的问题太笼统,不知你的TList类中装的内容是什麽
        在此给你一个装记录指针,对其中一项排序.