procedure TForm1.btn1Click(Sender: TObject);
var
  s, s1, so: string;
  Test: Boolean;
  i, j, k, n, vn: Integer;
  slMaterial3: TStringList;

  procedure ReadVoprAndOtv;
  begin
    slVopr.Append('');
    // Считываем вопросы
    while slMaterial3.Strings[n] <> '---' do
    begin
      if slMaterial3.Strings[n] <> '***' then
      begin
        so := slMaterial3.Strings[n];
        if so <> '' then
        begin
          if so[1] = ' ' then
            Delete(so, 1, 1);
          if (Pos('. ', so) <> 0) and
            ((Pos('. ', so) = 2) or (Pos('. ', so) = 3)) then
            Delete(so, 1, Pos('. ', so) + 1);
          if (AnsiUpperCase(Copy(so, 1, 2)) = 'A)') or (AnsiUpperCase(Copy(so, 1, 2)) = 'А)') then
            so := #13#9 + so;
          if (AnsiUpperCase(Copy(so, 1, 2)) = 'B)') or (AnsiUpperCase(Copy(so, 1, 2)) = 'В)') then
            so := #13#9 + so;
          if (AnsiUpperCase(Copy(so, 1, 2)) = 'C)') or (AnsiUpperCase(Copy(so, 1, 2)) = 'С)') then
            so := #13#9 + so;
          if (AnsiUpperCase(Copy(so, 1, 2)) = 'D)') or (AnsiUpperCase(Copy(so, 1, 2)) = 'Д)') then
            so := #13#9 + so;
          if (AnsiUpperCase(Copy(so, 1, 2)) = 'E)') or (AnsiUpperCase(Copy(so, 1, 2)) = 'Е)') then
            so := #13#9 + so;
        end;
        slVopr.Strings[slVopr.Count - 1] := slVopr.Strings
          [slVopr.Count - 1] + #13 + so;
      end
      else
      begin
        // ShowMessage(slVopr.Strings[slVopr.Count - 1]);
        slVopr.Append('');
      end;
      Inc(n)
    end;
    slVopr.Delete(slVopr.Count - 1);
    // ShowMessage(IntToStr(slVopr.Count));
    // Считываем ответы
    Inc(n);
    while Copy(slMaterial3.Strings[n], 1, 3) <> '---' do
    begin
      so := Trim(slMaterial3.Strings[n]);
      if so <> '' then
      begin
        slOtv.Append(so[Length(so)] + '-1');
      end;
      Inc(n)
    end;
  end;

begin
  slMaterial3 := TStringList.Create;
  slMaterial3.LoadFromFile('Material3.txt');
  n := 0;
  k := 0;
  while n < slMaterial3.Count do
  begin
    so := slMaterial3.Strings[n];
    if (Pos('---3.', slMaterial3.Strings[n]) <> 0) then
    begin
      slVopr.Clear;
      slOtv.Clear;
      Inc(k);
      tblTest.Close;
      tblTest.Filter := 'rLectNum=' + IntToStr(k);
      tblTest.Filtered := True;
      tblTest.Open;
      Inc(n, 4);
      ReadVoprAndOtv;
      for i := 0 to slVopr.Count - 1 do
      begin
        tblTest.Append;
        tblTest.FieldByName('rLectNum').AsInteger := k;
        tblTest.FieldByName('Num').AsInteger := tblTest.RecordCount + 1;
//        tblTest.FieldByName('Vopr').AsString := slVopr.Strings[i];
        edtVopr.Lines.Text := slVopr.Strings[i];
        tblTest.FieldByName('Otv').AsString := slOtv.Strings[i];
        tblTest.Post;
        Dec(n);
      end;
    end;
    Inc(n)
  end;

  slMaterial3.Free;
end;
