
15.12.2011, 01:48
|
Прохожий
|
|
Регистрация: 15.12.2011
Сообщения: 10
Репутация: 10
|
|
Решение проблемы с кодом
Помогите решить проблему, задача такая, нужно вводить количество строк, и столбцов с клавиатуры, и заполнить таблицу стринггрид тоже с клавиатуры и найти максимальный элемент...но проблема в том, что программа выдаёт ошибку raised exception class eaccessviolation и выделяет edt1.Text:=IntToStr(A[imax,jmax]); Помогите решить проблему.
Код:
unit Unit_masiv;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
edt1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
A: array of array of integer;
m, n: integer;
imax, jmax: integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var
i, j: integer;
begin
imax:=0;
jmax:=0;
For i:=0 to High(A) do
For j:=0 to High(A) do
if A[i,j] > A[imax,jmax] then begin
imax:=i;
jmax:=j;
end;
edt1.Text:=IntToStr(A[imax,jmax]);
end;
procedure TForm1.Button2Click(Sender: TObject);
Var
i, j: integer;
begin
if (Edit1.Text<>'') and (Edit2.Text<>'')
then
begin
n:=StrToInt(Edit1.Text);
m:=StrToInt(Edit2.Text);
for j:=0 to m do
for i:=0 to n do
if
Length(StringGrid1.Cells[i, j]) <>0
then
A[i,j]:=StrToInt(StringGrid1.Cells[i,j]);
StringGrid1.RowCount:=n;
StringGrid1.ColCount:=m;
end
else Showmessage('Ievadit masiva dimensiju.');
end;
end.
|