Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Error Dataset not in Insert or Edit Mode

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

like image 353
KE50 Avatar asked Jun 26 '13 06:06

KE50


1 Answers

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;
like image 193
Abhishek Avatar answered Sep 28 '22 23:09

Abhishek