работа с двумерным массивом в делфи
Добавлено: 19 ноя 2010, 23:19
суть задания заключается в том, что дана матрица НхМ. Требуется найти максимальный эл-т и поменять его местами с левым верхним (т.е. [1,1]). программа выдает ошибку
[syntax='Delphi']unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n,m:integer;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
n:=strtoint(edit1.text);
m:=strtoint(edit2.text);
stringgrid1.colcount:=n;
stringgrid1.rowcount:=m;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j, max, i1, j1, BBuf : integer;
a:array of array of integer;
begin
setlength(a, n, m);
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
a[i,j]:=strtoint(stringgrid1.Cells[i,j]);
end;
for i := 0 to n-1 do
for j := 0 to m-1 do
if a[i,j] > max then begin max :=a[i,j]; i1 := i; j1 := j end;
BBuf := a[0,0];
a[0,0] := a[i1,j1];
a[i1,j1] := BBuf;
for i:=0 to n-1 do
for j:=0 to m-1 do
stringgrid1.cells[i,j]:=inttostr(a[i,j]);
end;
end.[/syntax]

Помогите, пожалуйста, разобраться, в чем же ошибка)Variable 'max' might not have been initialized
Variable 'i1' might not have been initialized
Variable 'j1' might not have been initialized
[syntax='Delphi']unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n,m:integer;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
begin
n:=strtoint(edit1.text);
m:=strtoint(edit2.text);
stringgrid1.colcount:=n;
stringgrid1.rowcount:=m;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i,j, max, i1, j1, BBuf : integer;
a:array of array of integer;
begin
setlength(a, n, m);
for i:=0 to n-1 do
for j:=0 to m-1 do
begin
a[i,j]:=strtoint(stringgrid1.Cells[i,j]);
end;
for i := 0 to n-1 do
for j := 0 to m-1 do
if a[i,j] > max then begin max :=a[i,j]; i1 := i; j1 := j end;
BBuf := a[0,0];
a[0,0] := a[i1,j1];
a[i1,j1] := BBuf;
for i:=0 to n-1 do
for j:=0 to m-1 do
stringgrid1.cells[i,j]:=inttostr(a[i,j]);
end;
end.[/syntax]