Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CheckFile(var UserFile: TextFile; Size: Integer; Path: String): boolean;
- var
- I, Value: Integer;
- IsCorrect: Boolean;
- begin
- AssignFile(UserFile, Path);
- Reset(UserFile);
- IsCorrect := True;
- I := 0;
- while not(SeekEoLn(UserFile)) and IsCorrect do
- Begin
- Try
- Read(UserFile, Value);
- except
- IsCorrect := False;
- End;
- Inc(I);
- End;
- if I<>Size then
- IsCorrect := False;
- CloseFile(UserFile);
- CheckFile := IsCorrect;
- end;
- procedure TForm1.N4Click(Sender: TObject);
- var
- I, Size: Integer;
- UserFile: TextFile;
- Value: Integer;
- Path: String;
- begin
- Size := SpinEditMas.Value;
- Path := OpenDialog1.FileName;
- if OpenDialog1.Execute then
- Begin
- if CheckFile(UserFile, Size, Path) then
- begin
- AssignFile(UserFile, OpenDialog1.FileName);
- Reset(UserFile);
- for I := 0 to SpinEditMas.Value-1 do
- Begin
- Read(UserFile, Value);
- StringGrid1.Cells[i, 0] := IntToStr(Value);
- End;
- CloseFile(UserFile)
- end
- else
- MessageDlg('Данные в файле некорректны', mtError, [mbOK], 0)
- End;
- if Length(StringGrid1.Cells[0,0]) > 0 then
- Button2.Enabled := True;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement