сделал сортировку на одномерный массив, все работает, только чтоб сортировало, надо два раза нажать button4....вот код
	PHP код:
	
		
		
			
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;
type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button3: TButton;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
//    procedure Button2Click(Sender: TObject);
//    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
 N=3;
 P=15;
 var
 Form1: TForm1;
a:array [0..p]of integer;
i,j:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
randomize;
for i:=0 to p do
begin
a[i]:=random(100)-50;
stringGrid1.Cells[i,j]:=intToStr(a[i]);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i,m,k,c,j,max,min:integer;
begin
for i:=0 to 15 do
begin
k:=i;
for m:=i to 15 do if a[k]>a[m] then
 k:=m;
c:=a[i];
a[i]:=a[k];
a[k]:=c;
end;
stringGrid2.cells[i,0]:=IntToStr(c);
end;
end.
procedure TForm1.Button3Click(Sender: TObject);
var
max,min:integer;
begin
for i:=0 to 9 do
begin
for j:=0 to n do
if b[i] < min then
min:=b[i] else if b[i] > max then max:=b[i] ;
label1.caption:=IntToStr(max);
Label2.caption:=IntToStr(min);
end;
end; 
end. 
		
		
	 
 
использовал StringGrid-2шт, размером 1х16, button 4 шт(button2 и button 3 не работает, это для других целей)
Сделал сортировку на двумерный массив, (двумерный массив перевожу в одномерный, сортирую предыдущим кодом и готовый массив перевожу в двумерный массив), так вот, чтоб отсортировать, вставляю тот же код(предыдущего массива), но кнопка button2 нажимается только ОДИН раз т.е. на доконца сортирует, надо чтоб это кнопка нажималась ДВА раза, и все сортировало..................вот код
	Код HTML:
	unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;
type
  TForm1 = class(TForm)
    StringGrid2: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button3: TButton;
    Button4: TButton;
    StringGrid1: TStringGrid;
    StringGrid3: TStringGrid;
    StringGrid4: TStringGrid;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
//    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
const
 n=3;
var
 Form1: TForm1;
a:array [0..n,0..n] of integer;
b:array [0..n] of integer;
i,j:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
randomize;
for i:=0 to n do
for j:=0 to n do
begin
a[i,j]:=random(50)-10;
StringGrid1.cells[i,j]:=floatToStr(a[i,j]);
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i:integer;
begin
For i := 0 to 3 do StringGrid2.Cells[i, 0] := StringGrid1.Cells[i, 0];
For i := 4 to 7 do StringGrid2.Cells[i, 0] := StringGrid1.Cells[i-4, 1];
For i := 8 to 11 do StringGrid2.Cells[i, 0] := StringGrid1.Cells[i-8, 2];
For i := 12 to 16 do StringGrid2.Cells[i, 0] := StringGrid1.Cells[i-12, 3];
end;
procedure TForm1.Button2Click(Sender: TObject);
const
n=15;
var
b:array [0..n] of integer;
i,m,k,c,max,min:integer;
 begin
for i:= 0 to n do
b[i]:=StrToInt(StringGrid2.cells[i,0]);
begin
for i:=0 to 15 do
begin
k:=i;
for m:=i to 15 do if b[k]>b[m] then
 k:=m;
c:=b[i];
b[i]:=b[k];
b[k]:=c;
StringGrid3.cells[i,0]:=IntToStr(c);
end;
end;
 end;
procedure TForm1.Button5Click(Sender: TObject);
var
i:integer;
begin
 For i := 0 to 3 do StringGrid4.Cells[i, 0] := StringGrid3.Cells[i, 0];
 For i := 4 to 7 do StringGrid4.Cells[i-4, 1] := StringGrid3.Cells[i, 0];
 For i := 8 to 11 do StringGrid4.Cells[i-8, 2] := StringGrid3.Cells[i, 0];
 For i := 12 to 15 do StringGrid4.Cells[i-12, 3] := StringGrid3.Cells[i, 0];
 For i := 20 to 24 do StringGrid4.Cells[i-20, 4] := StringGrid3.Cells[i, 0];
end;
end.
 
использывал 4 StringGrid  два из них 1х16, а два 4х4, также кнопки dutton 5 шт
PS: мучаюсь уже 3 неделю, помогите пжлст
Заранее блогодарен