Advertisement
MaksNew

Untitled

Dec 19th, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.38 KB | None | 0 0
  1. function CheckFile(var UserFile: TextFile; Size: Integer; Path: String): boolean;
  2. var
  3.     I, Value: Integer;
  4.     IsCorrect: Boolean;
  5. begin
  6.     AssignFile(UserFile, Path);
  7.     Reset(UserFile);
  8.     IsCorrect := True;
  9.     I := 0;
  10.     while not(SeekEoLn(UserFile)) and IsCorrect do
  11.     Begin
  12.         Try
  13.             Read(UserFile, Value);
  14.         except
  15.             IsCorrect := False;
  16.         End;
  17.         Inc(I);
  18.     End;
  19.  
  20.     if I<>Size then
  21.         IsCorrect := False;
  22.  
  23.     CloseFile(UserFile);
  24.     CheckFile := IsCorrect;
  25. end;
  26.  
  27. procedure TForm1.N4Click(Sender: TObject);
  28. var
  29.     I, Size: Integer;
  30.     UserFile: TextFile;
  31.     Value: Integer;
  32.     Path: String;
  33. begin
  34.     Size := SpinEditMas.Value;
  35.     Path := OpenDialog1.FileName;
  36.     if OpenDialog1.Execute then
  37.     Begin
  38.         if CheckFile(UserFile, Size, Path) then
  39.         begin
  40.             AssignFile(UserFile, OpenDialog1.FileName);
  41.             Reset(UserFile);
  42.             for I := 0 to SpinEditMas.Value-1 do
  43.                 Begin
  44.                     Read(UserFile, Value);
  45.                     StringGrid1.Cells[i, 0] := IntToStr(Value);
  46.                 End;
  47.             CloseFile(UserFile)
  48.         end
  49.         else
  50.             MessageDlg('Данные в файле некорректны', mtError, [mbOK], 0)
  51.     End;
  52.     if Length(StringGrid1.Cells[0,0]) > 0 then
  53.         Button2.Enabled := True;
  54. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement