Показать сообщение отдельно
  #1  
Старый 23.12.2020, 00:26
arthur4564 arthur4564 вне форума
Прохожий
 
Регистрация: 23.12.2020
Сообщения: 1
Версия Delphi: Delphi 7
Репутация: 10
По умолчанию Помогите исправить

При закрытии программы, либо в любой момент проскакивают две ошибки. в чем может быть проблема?

invalid pointer operation

и

Project Project1.exe raised exception class EInvalidPointer with message 'Invalid pointer operation'. Process stopped. Use Step or Run to continue.

Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, Math, Registry;

type
  matr = array of array of real;
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    Edit1: TEdit;
    Button1: TButton;
    StringGrid3: TStringGrid;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
  public
  end;
  procedure Gaus(A:matr;B:array of real;Var X:array of real;n:integer;Var err:integer); stdcall; external 'DLL.dll';
var
  Form1: TForm1;
  Xt,Yt,Xp,Yp,B,X:array of real;
    A:matr;
    n,i,j,err,k:integer;
    g:textfile;
implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
begin
    n:=StringGrid1.RowCount;
    SetLength(A, n, n);
    SetLength(B, n);
    SetLength(X, n);
    For i:=0 to n-1 do
    Begin
      For j:=0 to n-1 do
      begin
        Val(StringGrid1.Cells[j,i], A[i,j], k);
        if k <> 0 then
        begin
          MessageBox(Handle, PAnsiChar('В ячейке матрицы A[' + IntTostr(j+1) + ', ' + IntToStr(i+1) + '] не число'), 'Внимание',	MB_OK+MB_ICONINFORMATION);
          Exit;
        end;
      end;
    End;
    For i:=0 to n-1 do
    Begin
    Val(StringGrid2.Cells[0,i], B[i], k);
    if k <> 0 then
    begin
      MessageBox(Handle, PAnsiChar('В ячейке столбцов свободных членов B[' + IntToStr(i+1) + '] не число'), 'Внимание',	MB_OK+MB_ICONINFORMATION);
Exit;
end;
    End;

    Gaus(A, B, x, n, err);
    if err <> 0 then
    begin
       MessageBox(Handle, 'Система уравнений не имеет решения', 'Внимание',	MB_OK+MB_ICONINFORMATION);
       Exit;
    end;
    For i:=0 to n-1 do
      StringGrid3.Cells[i,0]:=FloatToStrF(X[i], fffixed, 8, 2);
    AssignFile(g, 'out.txt');
    Rewrite(g);
    writeln(g,'Система уравнений');
    For i:=0 to n-1 do
    Begin
      For j:=0 to n-1 do
        write(g, a[i,j]:6:2,' ');
      writeln(g, '| ', b[i]:0:2);
    End;
    writeln(g,'Корни системы уравнений');
    For i:=0 to n-1 do
      write(g,x[i]:6:2,' ');
    CloseFile(g);
end;


procedure TForm1.Button2Click(Sender: TObject);

begin
    Val(Edit1.Text, n, i);
    if i <> 0 then
    begin
      MessageBox(Handle, 'Не корректное число ', 'Внимание',	MB_OK+MB_ICONINFORMATION);
      Exit;
    end;
    if (n<=0)or(n>10) then
    begin
      MessageBox(Handle, 'Число должно быть из отрезка [1..10]', 'Внимание',	MB_OK+MB_ICONINFORMATION);
      Exit;
    end;
    StringGrid1.RowCount:=n;
    StringGrid1.ColCount:=n;
    StringGrid2.RowCount:=n;
    StringGrid3.ColCount:=n;
    For i:=0 to n-1 do
     For j:=0 to n-1 do
      StringGrid1.Cells[j,i]:='';
    For i:=0 to n-1 do
    begin
      StringGrid2.Cells[0,i]:='';
      StringGrid3.Cells[i,0]:='';
    end;
end;


procedure TForm1.Button3Click(Sender: TObject);
begin
SetLength(a, n+1, n+1);
SetLength(b, n+1);
randomize;
for i:=1 to n do
for j:=1 to n do begin
a[i,j]:=1+random(100);
StringGrid1.Cells[j-1,i-1]:=FloatToStr(a[i,j]);
end;
for i:=1 to n do
for j:=1 to n do begin
b[i]:=1+random(100);
StringGrid2.Cells[0,i-1]:=FloatToStr(b[i]);
end;
end;
end.
Ответить с цитированием