写了 一个:这个需要循环很多次排序,是不是写的有问题:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Contnrs;Type TNameInfo = class(TPersistent) public FName : string; FSex : string; end; TWagerList = class(TObjectList) private function GetWager(wIndex: integer): TNameInfo; public property Wagers[windex:integer]: TNameInfo read GetWager; Function AddStore:boolean; end;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; MyWagerList : TWagerList;implementation{$R *.dfm}{ TWagerList }function TWagerList.AddStore: boolean;var WagerS : TNameInfo; i :integer;begin for i := 1 to 1000 do begin WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R5'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R4'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SS'; WagerS.FSex :='R5'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R4'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R3'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R5'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SS'; WagerS.FSex :='R5'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R4'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R3'; add(WagerS); WagerS := TNameInfo.Create; WagerS.FName :='SY'; WagerS.FSex :='R5'; add(WagerS); end;end;function TWagerList.GetWager(wIndex: integer): TNameInfo;begin begin if (wIndex < 0) or (wIndex >= Count) then begin result := nil; exit; end; Result := TNameInfo(Items[wIndex]);end;end;procedure TForm1.FormCreate(Sender: TObject);begin MyWagerList := TWagerList.Create; MyWagerList.AddStore;end;function TFieldHolderIndexSorter(ptOne, ptTwo: Pointer):Integer; var holderOne,holderTwo : TNameInfo; begin holderOne := TNameInfo(ptOne); holderTwo := TNameInfo(ptTwo); if holderOne.FName = holderTwo.FName then begin if (holderOne.FSex) <> (holderTwo.FSex) then result := 1 else if (holderOne.FSex) = (holderTwo.FSex) then result := 0 else result := -1; end else begin if (holderOne.FSex) <> (holderTwo.FSex) then result := 1 else if (holderOne.FSex) = (holderTwo.FSex) then result := 0 else result := -1; end end;procedure TForm1.Button1Click(Sender: TObject);var i :integer; Str: string;begin for i := 0 to 10 do MyWagerlist.Sort(@TFieldHolderIndexSorter);{ for i := 0 to 9999 do Str := Str + #13#10 + MyWagerList.Wagers.FName +'>>' + MyWagerList.Wagers.FSex; Memo1.Lines.Add( Str);}end;procedure TForm1.Button2Click(Sender: TObject);var i :integer; Str: string;begin for i := 0 to 9999 do Str := Str + #13#10 + MyWagerList.Wagers.FName +'>>' + MyWagerList.Wagers.FSex; Memo1.Lines.Add( Str);end;end.