form中拽3个memounit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;const MAXA1=20;type TSortArray=array[1..MAXA1] of integer; TSort=class private a1value: TSortArray; a1rate: TSortArray; function GetItemValue(index: Integer): integer; function GetItemRate(index: Integer): integer; public constructor Create(a1: TSortArray); procedure Sort(); property ItemsValue[index: Integer]: integer read GetItemValue ; property ItemsRate[index: Integer]: integer read GetItemRate ; end;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Memo2: TMemo; Memo3: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; a1: TSortArray; implementation{$R *.dfm}procedure random_a1();var i:integer;begin Randomize; for i:=1 to MAXA1 do begin a1:=random(10); end;end;procedure sort_a1();var i:integer;beginend;constructor TSort.Create(a1: TSortArray);var i,j:integer;begin for i:=1 to MAXA1 do a1value:=-1; for i:=1 to MAXA1 do a1rate:=0; for i:=1 to MAXA1 do begin for j:=1 to MAXA1 do begin if(a1value[j]<0) or (a1value[j]=a1) then begin break; end; end; a1value[j]:=a1; a1rate[j]:=a1rate[j]+1; end;end;procedure TSort.Sort();var i,j:integer; tmp:integer;begin for i:=1 to MAXA1 do begin for j:=i+1 to MAXA1 do begin if(a1rate<a1rate[j]) then begin tmp:=a1rate; a1rate:=a1rate[j]; a1rate[j]:=tmp; tmp:=a1value; a1value:=a1value[j]; a1value[j]:=tmp; end; end; end;end;function TSort.GetItemValue(index: Integer): integer;begin if((index<=0) or (index>MAXA1)) then result:=-1 else result:=a1value[index];end;function TSort.GetItemRate(index: Integer): integer;begin if((index<=0) or (index>MAXA1)) then result:=-1 else result:=a1rate[index];end;procedure TForm1.Button1Click(Sender: TObject);var i:integer; sort1:TSort;begin random_a1(); for i:=1 to MAXA1 do memo1.Lines.Add(inttostr(a1)); sort1:=TSort.Create(a1); for i:=1 to MAXA1 do if(sort1.GetItemValue(i)>=0) then memo2.Lines.Add(inttostr(sort1.GetItemValue(i))+'--'+inttostr(sort1.GetItemRate(i))); sort1.Sort(); for i:=1 to MAXA1 do if(sort1.GetItemValue(i)>=0) then memo3.Lines.Add(inttostr(sort1.GetItemValue(i))+'--'+inttostr(sort1.GetItemRate(i)));end;end.