Delphi Error Dataset not in Insert or Edit Mode

最后都变了- 提交于 2020-04-12 19:51:12

问题


Objective:

  1. Click on the button on the TRxDBCombo to call a search box
  2. On Selecting the record from search box, the result is set as Field Value for the TComboEditBox and is posted in the TRxMemoryData Dataset

The Error:

Dataset not in Insert or Edit Mode appears the second time of calling this function

TDBEditBox1.SetFocus;
Form_Search:= TForm_Search.Create(Application);
with Form_Search do
  Begin
    showmodal;
    //Get Result from Database
    if trim(TempResult) <> '' then
      Begin
        TDBEditBox1.Field.Value := MResult;
      End;
  End;

The setup includes:

  1. A TJvDBGrid with the Data Source connected to a TDataSource
  2. The TDataSource is Connected to a TRxMemoryData
  3. A TRxDBComboEdit with its Data Source set to the TDataSource in step 2 above

Please assist


回答1:


The error is coming because of the following line: TDBEditBox1.Field.Value := MResult; at this line your dataset is not in Insert or Edit mode. You can add following check to avoid this error:

if not (TDBEditBox1.DataSource.DataSet.State in [dsEdit, dsInsert]) then
begin
  TDBEditBox1.DataSource.DataSet.Edit;
  // Or TDBEditBox1. DataSource.DataSet.Insert; depending on the operation you are doing (Edit or Insert) 
end;
TDBEditBox1.Field.Value := MResult;


来源:https://stackoverflow.com/questions/17312949/delphi-error-dataset-not-in-insert-or-edit-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!