unitmysort; interface usesClasses;//TThread类在Classes中被定义。 type PSortArray=TSortArray; TSortArray=array.[0..MaxIntdivSize?? Of(Integer)-1]ofInteger; {此处定义了TsortThread类} TSortThread=class(TThread) PRivate {在TSortThread类中定义了如下几个私有变元} fsortArray:PSortArray; FSize:Integer; FA,FB,FI,FJ:Integer; Protected {类TSortThread超越了类Tthread的Execute方法} procedure Execute;override; {类TsortThread添加了一个Sort方法} procedure Sort(varA:arrayofInteger); public {类TSortThread超越了类Tthread的构造方法} constructorCreate(varSortArray:arrayofInteger); end; implementation constructorTSortThread.Create(varSortArray:arrayofInteger); begin FSortArray:=@SortArray; FSize:=High(SortArray)-Low(SortArray)+1; FreeOn Terminate:=True; inheritedCreate(False); end; {当线程开始时,Execute方法将被调用。} procedure TSortThread.Execu?? te; begin Sort(Slice(FSortArray,FSize)); end; {下面实现了冒泡法排序} procedure TSortThread.Sort(varA:arrayofInteger); var I,J,T:Integer; begin for I:=High(A)downto Low(A) do for J:=Low(A)to High(A)-1 do if A[J]>A[J+1] then begin T:=A[J]; A[J]:=A[J+1]; A[J+1]:=T; if Terminated then Exit; end; end; end