Skyp Posted January 22, 2023 Share Posted January 22, 2023 There is a form on which there is a TvirtualTable (Unidac package) or Tfdmemtable (FireDAC package)(tried both). uniDBCheckBox components bound to DataSource: When changing the DataSource, I try to edit adjacent records in the same DataSet (code onAfterEdit): procedure TUFrameTreeRulesF.FFrmStructVTableAfterEdit(DataSet: TDataSet); procedure MainUpd; procedure UpdateRefresh(aIsEnabled, aIsNotifyInface, aIsNotifyEMail: Boolean; aParentStr: string); var lvq: TVirtualQuery; /// throught query (localSQL) lwherestr: string; const CDefUpdateParentStr : string = 'UPDATE source SET %s WHERE (idname=:pname OR idname LIKE :pname2) OR id=:pname;'; begin lwherestr := EmptyStr; lvq := TVirtualQuery.Create(nil); try lvq.SourceDataSets.Add(FFrmStruct.VTable, 'source'); if FIsEnabledChange then begin lwherestr := lwherestr + 'isEnabled = :pIsEnabled'; end; if FIsNotifyInfaceChange then begin lwherestr := ifthen(lwherestr.IsEmpty, EmptyStr, ',') + 'IsEnableNotifyInface =:pIsEnableNotifyInface'; end; if FIsNotifyEMailChange then begin lwherestr := ifthen(lwherestr.IsEmpty, EmptyStr, ',') + 'IsEnabledNotifyEmail=:pIsEnabledNotifyEmail'; end; if not lwherestr.IsEmpty then begin lvq.sql.Text := Format(CDefUpdateParentStr, [lwherestr]); lvq.ParamByName('pname').AsString := aParentStr; lvq.ParamByName('pname2').AsString := aParentStr + '%'; if FIsNotifyEMailChange then lvq.ParamByName('pIsEnabledNotifyEmail').AsBoolean := aIsNotifyEMail; if FIsNotifyInfaceChange then lvq.ParamByName('pIsEnableNotifyInface').AsBoolean := aIsNotifyInface; if FIsEnabledChange then lvq.ParamByName('pIsEnabled').AsBoolean := aIsEnabled; lvq.Prepare; try lvq.Execute; except on e: exception do lwherestr := e.message; /// check end; end; finally if Assigned(lvq) then lvq.Destroy; lvq := nil; end; end; var lubookmark: TBookmark; lparentid: string; begin FFrmStruct.VTable.AfterEdit := nil; lubookmark := FFrmStruct.VTable.Bookmark; FFrmStruct.UDbBuissnesObjectTree.BeginUpdate; FFrmStruct.VTable.DisableControls; FIsChangeSel := True; if not FFrmStruct.VTable.FieldByName('idname').AsString.IsEmpty then lparentid := FFrmStruct.VTable.FieldByName('idname').AsString else lparentid := FFrmStruct.VTable.FieldByName('id').AsString; FFrmStruct.VTable.edit; UpdateRefresh(UDBChBox.Checked, UDBCBNotifyInface.Checked, UDBCheckBoxNotifyEmail.Checked, lparentid); FFrmStruct.VTable.post; FFrmStruct.UDbBuissnesObjectTree.Refresh; FFrmStruct.VTable.EnableControls; FFrmStruct.UDbBuissnesObjectTree.EndUpdate; FFrmStruct.VTable.AfterEdit := FFrmStructVTableAfterEdit; if Assigned(lubookmark) then FFrmStruct.VTable.GotoBookmark(lubookmark); self.hidemask; end; begin self.ShowMask('Обновляю данные...'); FIsEnabledChange := not FFrmStruct.BeforeIsEnabledChange = UDBChBox.Checked; FIsNotifyInfaceChange := not FFrmStruct.BeforeisNotifyChange = UDBCBNotifyInface.Checked; FIsNotifyEMailChange := not FFrmStruct.BeforeIsNotifyEmail = UDBCheckBoxNotifyEmail.Checked; MainUpd; UBtnApplySetting.Enabled := True; end; After I get the error : "DataSet not in Edit or Insert mode" =( At the same time, after the error occurred, the DataSet was updated (as expected, the code above worked (it works)). I have an error happening in the UniDbCheckBox.pas module: I quickly corrected this via a "crutch" (hack): Version: 1.90.0.1564 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.