|  | 
 
 | 
| 
 | |||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны | 
|  | 
|  | Опции темы | Поиск в этой теме | Опции просмотра | 
|  | 
| 
			 
			#1  
			
			
			
			
		 | |||
| 
 | |||
|  Перемножение матриц размерностью MxN NxQ Помогите, пожалуйста, разобраться почему на запуск моей програмки выходит ошибка exception class EConvertError with message ''' is not a valid integer value'.  Сама задача проста: перемножить матрицу А размерностью MxN на матрицу B размерностью NxQ. Код программы: Код: procedure TForm1.Edit1Change(Sender: TObject);
var m:integer;
begin
if Edit1.Text<>'' then
begin
 m:=strtoint(Edit1.Text);
 StringGrid1.RowCount:=m;
 StringGrid3.RowCount:=m;
 StringGrid1.Visible:=true;
 StringGrid3.Visible:=true;
end
else
 begin
 StringGrid1.Visible:=false;
 StringGrid3.Visible:=false;
 end;
end;
procedure TForm1.Edit2Change(Sender: TObject);
var n: integer;
begin
if Edit2.Text<>'' then
begin
 n:=strtoint(Edit2.Text);
 StringGrid1.ColCount:=n;
 StringGrid2.RowCount:=n;
 Edit3.Text:=Edit2.Text ;
 StringGrid1.Visible:=true;
 StringGrid2.Visible:=true;
 end
else
 begin
 StringGrid1.Visible:=false;
 StringGrid2.Visible:=false;
 end;
end;
procedure TForm1.Edit4Change(Sender: TObject);
var q: integer;
begin
if Edit4.Text<>'' then
begin
 q:=strtoint(Edit4.Text);
 StringGrid2.ColCount:=q;
 StringGrid3.ColCount:=q;
 StringGrid2.Visible:=true;
 StringGrid3.Visible:=true;
end
else
 begin
 StringGrid2.Visible:=false;
 StringGrid3.Visible:=false;
 end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var a,b,x: array [0..100,0..100] of integer;
 i,j,l: integer;
 m,n,q:integer;
begin
// считываем матрицы с гридов
m:=StrToInt(Edit1.Text);
n:=StrToInt(Edit2.Text);
q:=StrToInt(Edit4.Text);
  for i:=1 to m do 
    for j:=1 to n do 
      a[i,j] := StrToInt(StringGrid1.Cells[i,j]);
  for i:=1 to n do 
    for j:=1 to q do 
       b[i,j] := StrToInt(StringGrid2.Cells[i,j]);
// перемножение матрицы
  For i:= 1 to m do
    For j:= 1 to q do
          Begin
          x[i,j]:=0;
           For l:= 1 to n do
           begin
             x[i,j]:=x[i,j]+a[l,i]*b[j,l];
           end;
           end;
// отображение матрицу в 3-ем гриде
   for i:=1 to m do
   begin
     for j:=1 to q do
     begin
     StringGrid3.cells[i,j]:=IntToStr(x[i,j]);
     end;
   end;
end;
end. | 
| 
			 
			#2  
			
			
			
			
		 | ||||
| 
 | ||||
|   Где-то у тебя Integer нужен =) наверное реакция на StrToInt когда вводишь что-то аля "аыв34" то трудно переобразовать его в Integer. Попробуй использовать TryStrToInt - функция со встроеной проверкой, если чё-то не конвертирует то ризалт False от функции, а не КонвертЕррор от винды =) | 
| 
			 
			#3  
			
			
			
			
		 | |||
| 
 | |||
|   Цитата: 
 Нет, точно ввожу цифры.... и чего она не понимает  ( | 
| 
			 
			#4  
			
			
			
			
		 | ||||
| 
 | ||||
|   на какую строчку ругается? | 
| 
			 
			#5  
			
			
			
			
		 | |||
| 
 | |||
|   Прошлась по шагам (F7) и когда выхожу со строчки с  a[i,j] := StrToInt(StringGrid1.Cells[i,j]); вышла эта ошибка. Здесь я считываю значения с грида 1 for i:=1 to m do for j:=1 to n do a[i,j] := StrToInt(StringGrid1.Cells[i,j]); for i:=1 to n do for j:=1 to q do b[i,j] := StrToInt(StringGrid2.Cells[i,j]); | 
| 
			 
			#6  
			
			
			
			
		 | ||||
| 
 | ||||
|   У нее ругается на пустую ячейку. Попробуй так: Код:  for i:=1 to m - 1 do 
    for j:=1 to n - 1 do Последний раз редактировалось BoRoV, 12.12.2010 в 18:39. |