Get old value of modified field on TMSQuery.AfterUpdateExecute event

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
brace
Posts: 227
Joined: Wed 14 Feb 2007 08:26

Get old value of modified field on TMSQuery.AfterUpdateExecute event

Post by brace » Mon 29 Jul 2019 08:56

How i can get the old value of a modified field in the TMSQuery.AfterUpdateExecute event?

i can get the field name with "Params.Items.Name" and the value with "Params.Items.Value", i would like to get the "Old value" too.

Code: Select all

//code sample to get fieldname and value of modified field

procedure TForm1.MyQueryAfterUpdateExecute(
  Sender: TCustomMSDataSet; StatementTypes: TStatementTypes; Params: TMSParams);
var
  I : Integer;
  sFieldName : string;
  vValue : Variant;
begin
  inherited;
  if StatementTypes = [stUpdate]  then
  begin
    for I := 0 to Params.Count-1 do
    begin
    // Get modified field name
      sFieldName := Params.Items[I].Name;          
    // Get value of modified field
      vValue := Params.Items[I].Value;
    end;
  end;
end;

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: Get old value of modified field on TMSQuery.AfterUpdateExecute event

Post by Stellar » Mon 29 Jul 2019 14:07

Unfortunately, there's no way to obtain the old values of the modified fields in the dataset after the changes have been saved on the server.
You can get the necessary data before applying the changes, e.g.

Code: Select all

procedure TForm1.MSQuery1BeforeUpdateExecute(Sender: TCustomMSDataSet;
  StatementTypes: TStatementTypes; Params: TMSParams);
var
  i: Integer;
  Field: TField;
begin
  if StatementTypes <> [stUpdate]  then
    Exit;

  for i := 0 to Sender.FieldCount - 1 do begin
    Field := Sender.Fields[i];
    if Field.OldValue <> Field.Value then
      Memo1.Lines.Add(Field.FieldName + ': Old = ' + VarToStr(Field.OldValue) + ', New = ' + VarToStr(Field.Value));
  end;
end;

Post Reply