Page 1 of 1

Can I get changed fields from a dataset

Posted: Fri 13 Apr 2012 09:31
by LarsGeisler
Hello,

for logging purposes, I would like to get a list of the changed fields in a dataset, as the update is sent to the DB server.

The UnisSQLMonitor component, can deliver text which contains the info, but I was wondering if there is a more straightforward way to do it.

Best regards Lars Geisler

Posted: Fri 13 Apr 2012 12:27
by AndreyZ
Hello,

To get modified fields, you can use the following code in the BeforeUpdateExecute event handler:

Code: Select all

procedure TMainForm.UniQueryBeforeUpdateExecute(Sender: TDataSet;
  StatementTypes: TStatementTypes; Params: TDAParams);
var
  str: TStringList;
  i: integer;
begin
  str := TStringList.Create;
  try
    for i := 0 to Sender.FieldCount - 1 do
      if Sender.Fields[i].NewValue  Sender.Fields[i].OldValue then
        str.Add(Sender.Fields[i].FieldName);
    ShowMessage('Modified fields: ' + #13#10 + str.Text);
  finally
    str.Free;
  end;
end;

Great - just what i want!!

Posted: Fri 13 Apr 2012 12:45
by LarsGeisler
Thank you :D