delphi 数据集未处于编辑或插入模式

3yhwsihp  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(492)

我是堆栈溢出的新用户。我有一个大项目,我不断得到同样的错误。我试图加载数据到我的数据库,无论我尝试多少次或我改变我仍然得到同样的错误。我已经标记nessarry变量,尝试tbl().Edit和tbl().Insert内部,外部我的循环和在情况下,但我似乎仍然得到同样的错误。
“玩家1”、“玩家2”、“分数1”、“分数2”是全局变量。

procedure TfrmInvigilator.btnSubmitClick(Sender: TObject);
Var
  i, j, iRound: Integer;
begin
  sPlayer1 := cmbName1.Text; // Assigning values to variables for cmbPlayers
  sPlayer2 := cmbName2.Text;

  iScore1 := sedScore1.Value; // Assigning values to variables for sedScores
  iScore2 := sedScore2.Value;

  iRound := cmbRound.ItemIndex; // Assigning values to variable for cmbRound

  if (cmbName1.ItemIndex = -1) then
  // Displays show message if cbmName1 is blank
  begin
    ShowMessage('Please select player name');
  end
  else
  begin // If cbmName1 is not blank then:
    i := pos(' ', sPlayer1); // Find position of ' ' in cbmName1.Text
    sPlayer1 := Copy(sPlayer1, 1, i - 1); // sPlayer1 := Name of player

    dmChess.tblPlayerInfo.Locate('Name', sPlayer1, []); // Locates Name in table
    Num1 := dmChess.tblPlayerInfo['ID']; // Retrives ID of player

    with dmChess do
    begin
      tblScoreboard.First;

      while NOT tblScoreboard.EOF do
      begin
        tblScoreboard.Locate('ID', Num1, []);

        case iRound of
          0:
              tblScoreboard['Round 1A'] := iScore1;
          1:
              tblScoreboard['Round 1B'] := iScore1;
          2:
              tblScoreboard['Round 1C'] := iScore1;
          3:
              tblScoreboard['Round 1D'] := iScore1;
          4:
              tblScoreboard['Round 2'] := iScore1;
          5:
              tblScoreboard['Semi-Final'] := iScore1;
          6:
              tblScoreboard['Final'] := iScore1;
        end;

        tblScoreboard.Post;
      end;
    end;
  end;

   if (cmbName2.ItemIndex = -1) then
   // Displays show message if cbmName2 is blank
   begin
   ShowMessage('Please slecet player name');
   end
   else
   begin // If cbmName2 is not blank then:
   j := pos(' ', sPlayer2); // Find position of ' ' in cbmName2.Text
   sPlayer2 := Copy(sPlayer2, 1, j - 1); // sPlayer2 := Name of player

   dmChess.tblPlayerInfo.Locate('Name', sPlayer2, []); // Locates Name in table
   Num1 := dmChess.tblPlayerInfo['ID']; // Retrives ID of player
   end;

end;

`

qybjjes1

qybjjes11#

您不能只在DataSet field(数据表或查询)中设定新值,数据集必须知道您要变更目前的数据录或插入新的数据录。例外状况会告诉您这一点。如何解决:在对数据集中的任何字段进行更改之前,您需要设置所需的模式。DataSet.edit;-编辑当前记录,DataSet.Insert-在当前位置插入新记录,DataSet.Append-在末尾添加新记录。对于此代码片段,将tblScoreboard.Edit;行添加到tblScoreboard.Locate('ID', Num1, []);DataSet.Post行之后-将当前更改保存到记录中,并将数据集模式改回浏览

相关问题