Вот весь код:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, Grids, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label4: TLabel;
Edit4: TEdit;
Label5: TLabel;
StringGrid1: TStringGrid;
Label6: TLabel;
Edit5: TEdit;
Edit6: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
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;
var
Form1: TForm1;
Y:array of array of integer;
C:array of array of real;
n:integer;
m:integer;
k:integer;
l:integer;
implementation
uses unit2,unit3;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
edit1.Text:=inttostr(n);
edit5.Text:=inttostr(m);
edit6.Text:=inttostr(l);
edit4.text:=inttostr(k);
stringgrid1.RowCount:=n;
stringgrid1.ColCount:=m;
end;
procedure
TForm1.Button2Click(Sender: TObject);
var i,j,t:integer;
begin
m:=stringgrid1.ColCount;
k:=strtoint(edit4.text)-1;
l:=strtoint(edit6.text)-1;
if (k=-1) then
begin
showmessage('Перестановка столбцов невозможно, проверьте введеные данные!');
exit;
end;
if (l=-1) then
begin
showmessage('Перестановка столбцов невозможно, проверьте введеные данные!');
exit;
end;
if (k>m-1) then
begin
showmessage('Перестановка столбцов невозможно, проверьте введеные данные!');
exit;
end;
if (l>m-1) then
begin
showmessage('Перестановка столбцов невозможно, проверьте введеные данные!');
exit;
end;
for i:=0 to n-1 do
begin
t:=Y[i,k];
Y[i,k]:=Y[i,l];
Y[i,l]:=t;
end;
for t:=0 to n-1 do
for j:=0 to m-1 do
stringgrid1.Cells[j,t]:=inttostr(Y[t,j]);
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
begin
n:=strtoint(edit1.Text);
m:=strtoint(edit5.Text);
setlength(Y,n,m);
stringgrid1.RowCount:=n;
stringgrid1.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
Y[i,j]:=random(50--50+1)-50;
stringgrid1.Cells[j,i]:=inttostr(Y[i,j]);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.Button5Click(Sender: TObject);
var i,j:integer;
begin
n:=strtoint(edit1.Text);
m:=strtoint(edit5.Text);
n:=12;
m:=9;
setlength(C,n,m);
stringgrid1.RowCount:=n;
stringgrid1.ColCount:=m;
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
C[i,j]:=cos(14*j+1);
stringgrid1.Cells[j,i]:=FormatFloat('0.00',C[i,j]);
end;
end;
procedure
TForm1.Button4Click(Sender: TObject);
var i,j:integer;
tmp:real;
begin
m:=stringgrid1.ColCount;
k:=strtoint(edit4.text)-1;
l:=strtoint(edit6.text)-1;
k:=0;
l:=8;
for i:=0 to n-1 do
begin
tmp:=C[i,k];
C[i,k]:=C[i,l];
C[i,l]:=tmp;
end;
for tmp:=0 to n-1 do
for j:=0 to m-1 do
stringgrid1.Cells[j,tmp]:=FormatFloat('0.00',C[tmp,j]);
end;
end.
Все работает до этого момента....
Код:
procedure
TForm1.Button4Click(Sender: TObject);
var i,j:integer;
temp:real;
begin
m:=stringgrid1.ColCount;
k:=strtoint(edit4.text)-1;
l:=strtoint(edit6.text)-1;
k:=0;
l:=8;
for i:=0 to n-1 do
begin
temp:=C[i,k];
C[i,k]:=C[i,l];
C[i,l]:=temp;
end;
for tmp:=0 to n-1 do
for j:=0 to m-1 do
stringgrid1.Cells[j,temp]:=FormatFloat('0.00',C[temp,j]);
end;
|