views:

331

answers:

1

I have Midas project that uses a TDataSetProvider in one of RemoteDataModules in the Server

Currently I am making use of the following events

  • BeforeApplyUpdates - to create an Object
  • BeforeUpdateRecord - to use the object
  • AfterApplyUpdates - to destory the object

Question:

Will ‘ AfterApplyUpdates’ always be called even if the is an update error ?

+9  A: 

If you look at the sourcecode:

function TCustomProvider.DoApplyUpdates(const Delta: OleVariant; MaxErrors: Integer;
  out ErrorCount: Integer; var OwnerData: OleVariant): OleVariant;
begin
  SetActiveUpdateException(nil);
  try
    try
      if Assigned(FOnValidate) then
        FOnValidate(Delta);
      DoBeforeApplyUpdates(OwnerData);
      Self.OwnerData := OwnerData;
      try
        Result := InternalApplyUpdates(Delta, MaxErrors, ErrorCount);
      finally
        OwnerData := Self.OwnerData;
        Self.OwnerData := unassigned;
      end;
    except
      on E: Exception do
      begin
        SetActiveUpdateException(E);
        raise;
      end;
    end;
  finally
    try
      DoAfterApplyUpdates(OwnerData);
    finally
      SetActiveUpdateException(nil);
    end;
  end;
end;

Yoy see that DoAfterApplyUpdates is called in the finally block. This means it is always called regardles of any exception.

Gamecat