Jump to content

Bug (in Unigui) - "DataSet not in Edit or Insert mode" on event "onAfterEdit"


Skyp

Recommended Posts

There is a form on which there is a TvirtualTable (Unidac package) or Tfdmemtable (FireDAC package)(tried both).

uniDBCheckBox components bound to DataSource:

image.thumb.png.e83118e1f8e5544fe8d1d19ab550be60.png
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):

image.png.d249195bd24ad571371fec8004290047.png

 

Version:  1.90.0.1564 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...