PROGRAM Bad1;

TYPE
  DAFile = File [0..5] of Integer;
VAR
  MyFile : bindable DAFile;

procedure AssignFile;
var
  b : BindingType;
begin
  unbind(MyFile);
  b := binding(MyFile);
  b.name := 'test.dat';
  bind(MyFile,b);
end;

procedure CreateFile;
var
  i : Integer;
begin
  AssignFile;
  Rewrite(MyFile);
  for i := 0 to 5 do
    Write(MyFile,i);
  Close(MyFile);
end;


procedure ModifyFile(index : Integer; val : Integer);
var
  pos : Integer;
begin
  AssignFile;
  SeekWrite(MyFile,Index);
  pos := Position(MyFile);
  Write(MyFile,val);
  Close(MyFile);
end;

procedure CheckFile;
var
{$w-}
  result: array[0..5] of integer = (0:55, 1:1, 2:66, 3:3, 4:4, 5:5);
{$w+}
  i,val,pos : Integer;
begin
  AssignFile;
  for i := 0 to 5 do
  begin
    SeekRead(MyFile,i);
    pos := Position(MyFile);
    Read(MyFile,val);
    if (pos <> i) or (val <> result[i]) then
      begin
        WRITELN('Failed ',i,' : ',pos,', ',val);
        Halt
      end
  end;
  Close(MyFile);
end;

begin
  CreateFile;
  ModifyFile(0,55);
  ModifyFile(2,66);
  ModifyFile(6,77);
  CheckFile;
  writeln('OK')
end.
