Can I get changed fields from a dataset

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
LarsGeisler
Posts: 10
Joined: Fri 25 Jun 2010 09:00
Location: Denmark

Can I get changed fields from a dataset

Post by LarsGeisler » Fri 13 Apr 2012 09:31

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

AndreyZ

Post by AndreyZ » Fri 13 Apr 2012 12:27

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;

LarsGeisler
Posts: 10
Joined: Fri 25 Jun 2010 09:00
Location: Denmark

Great - just what i want!!

Post by LarsGeisler » Fri 13 Apr 2012 12:45

Thank you :D

Post Reply