问题
Objective:
- Click on the button on the TRxDBCombo to call a search box
- 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:
- A TJvDBGrid with the Data Source connected to a TDataSource
- The TDataSource is Connected to a TRxMemoryData
- 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