Board index » delphi » Capturing Field Changes & Field Names

Capturing Field Changes & Field Names

Is there any generic way to capture which fields in
a record have been changed and to what?

After a record has been modified, I would like to get
the field(s) which where changed, the original values,
and the final values. Thank you.

 

Re:Capturing Field Changes & Field Names


Create a BeforeEdit event handler and save the field values in a variant
array. You can then compare these values to the values in the record in your
BeforePost event handler to see what has changed.

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to questions received via email)

Re:Capturing Field Changes & Field Names


Quote
>Is there any generic way to capture which fields in
>a record have been changed and to what?

>After a record has been modified, I would like to get
>the field(s) which where changed, the original values,
>and the final values. Thank you.

If you use CachedUpdates there is an Oldvalue property of the tfields that gets
the value prior to modification.
In any other case you will have to store the old values with your own code.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Capturing Field Changes & Field Names


Thank you. Is this process that straightforward?  Is
there anything special I should be aware of.

I saw something in the documentation referring to an
ARRAYOFCONST macro (?) but cannot find anything else
on it.

Bill Todd <b...@nospam.dbginc.com> wrote in article
<7mu0vd$dl...@forums.borland.com>...

Quote
> Create a BeforeEdit event handler and save the field values in a variant
> array. You can then compare these values to the values in the record in
your
> BeforePost event handler to see what has changed.

> Bill

> --

> Bill Todd - TeamB
> (TeamB cannot respond to questions received via email)

Re:Capturing Field Changes & Field Names


What are the situations in which I would want to use/avoid using
cachedupdates? Thanks.

Quote
> If you use CachedUpdates there is an Oldvalue property of the tfields
that gets
> the value prior to modification.
> In any other case you will have to store the old values with your own
code.

Re:Capturing Field Changes & Field Names


Quote
>What are the situations in which I would want to use/avoid using
>cachedupdates? Thanks.

Cached updates are most useful when you need to work with a query that can not
return a live answer set.   In addition to that if you want to be able to edit a
batch of records and have the option to save or abandon the changes cached
updates are one way to do this.
Cached updates can be difficult to use especially if you are trying to cache
both master and Detail records.
If you have the Delphi client server version you probably want to use
Tclientdataset instead of cached updates.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Capturing Field Changes & Field Names


Just use a variant array to hold the data.

var
  Rec:  Variant;
begin
  VarArrayCreate([0, Table1.FieldCount - 1], varVariant);
  for I := 0 to Table1.FieldCount - 1 do
    Rec[I] := Table1.Fields[I].Value;

Bill

--

Bill Todd - TeamB
(TeamB cannot respond to questions received via email)

Other Threads