Page 1 of 1

TZQuery 'NewValue' and 'OldValue'

Posted: 17.06.2014, 02:30
by elidorio2
Hello Guys,

I am in need of aid, how to use the function in TZQuery 'NewValue' and 'OldValue'. I need to upgrade the value is changed.
Thanks for the help.

Edson

Re: TZQuery 'NewValue' and 'OldValue'

Posted: 17.06.2014, 15:43
by cacofony
Could you clarify further? How to use NewValue and OldValue?

http://stackoverflow.com/questions/1971 ... as-streams


function FieldChanged(DataSet: TDataSet; FieldName: string): Boolean;
var
fld: TField;
begin
fld := DataSet.FieldByName(FieldName);

if fld.IsBlob then
Exit((fld as TBlobField).Modified);

if (fld.OldValue = Null) and (fld.NewValue = Unassigned) then // This happens when a NULL field does not change
Exit(False)
else
Exit(fld.OldValue <> fld.NewValue);
end;

Re: TZQuery 'NewValue' and 'OldValue'

Posted: 17.06.2014, 15:55
by elidorio2
Had tried to do this way In Event "BeforPost" the query:
Note: I need to compare a value if the value changes I perform a procedure:

if qryForm.State in [dsEdit] then
qryFormvlr_serv.OldValue;

if qryFormvlr_serv.OldValue <> qryFormvlr_serv.NewValue then
begin
verifica_status;
end;

Re: TZQuery 'NewValue' and 'OldValue'

Posted: 20.06.2014, 16:45
by cacofony
I use something like this, ZQuery, MySQL

Code: Select all

OnBeforePost
var
OldValue : variant;
begin
if Self.State in [dsEdit] then
    begin
      if not FieldByName('taskstatusid').IsNull then
      begin
      OldValue := FieldByName('taskstatusid').OldValue;
       if VarIsOrdinal(OldValue) then
        begin
          if  FieldByName('taskstatusid').AsInteger <> VarAsType(OldValue, VarType(OldValue)) then
        begin
          // Status has changed.
        end;
        end;
     end;
end;