Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.61 KB | None | 0 0
  1. procedure TProgramm3_3.OpenFileClick(Sender: TObject);
  2. var
  3.    NewMatrix: TMatrix;
  4.    i, j, Max: Integer;
  5.    Check: string;
  6.    InputFile: TextFile;
  7.    Error, isCorrect: Boolean;
  8. begin
  9.    if OpenFileToRead.Execute then
  10.    begin
  11.       isCorrect := True;
  12.       AssignFile(InputFile, OpenFileToRead.FileName);
  13.       Reset(InputFile);
  14.       If SeekEof(InputFile) then
  15.       begin
  16.          MessageDlg('Файл пуст', mtError,[mbOK],0);
  17.          isCorrect := False;
  18.       end
  19.       else
  20.       begin
  21.          isCorrect := True;
  22.          try
  23.             i := -1;
  24.             while (not EoF(InputFile)) and (i < 8) do
  25.             begin
  26.                Inc(i);
  27.                SetLength(NewMatrix, i + 1);
  28.                j := -1;
  29.                while not (SeekEoLn(InputFile)) and (j < 8) do
  30.                begin
  31.                   Inc(j);
  32.                   SetLength(NewMatrix[i], j + 1);
  33.                   Read(InputFile, NewMatrix[i, j]);
  34.                end;
  35.                Readln(InputFile);
  36.             end;
  37.          except
  38.             ShowMessage('Некорректные данные в файле');
  39.             isCorrect := False;
  40.          end;
  41.       end;
  42.       if isCorrect then
  43.       begin
  44.          if i < j then
  45.             SetLength(NewMatrix, i+1, i+1)
  46.          else
  47.             SetLength(NewMatrix, j+1, j+1);
  48.          Order.Text := IntToStr((Length(NewMatrix)));
  49.          for i := 0 to Length(NewMatrix)-1 do
  50.             for j := 0 to Length(NewMatrix[0])-1 do
  51.             begin
  52.                Matrix.Cells[j, i] := IntToStr(NewMatrix[i, j]);
  53.             end;
  54.       end;
  55.    end;
  56. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement