Compare xrec to rec

JohnConJohnCon Member Posts: 55
Is it possible to compare all of xrec to rec rather than by field?
It tried if rec<>xrec then
but it wont let you do that.

Comments

  • DenSterDenSter Member Posts: 8,307
    My guess is that if it doesn't work then it must not be possible to do it that way :mrgreen:
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
  • David_SingletonDavid_Singleton Member Posts: 5,479
    :?:

    Why can't you just use :
    If format(xRec) <> format(rec) then
      message('The record was changed');
    

    Other wise you would have to go through each field individually.
    David Singleton
  • wonmowonmo Member Posts: 139
    A way to do this is to create a global variable to temporarily store the "before" values (eg. global_var := Rec;) and then just compare, using the recordref and fieldref variable types, any differences between the global variable record to Rec. I've used this quite often and it works well.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    wonmo wrote:
    A way to do this is to create a global variable to temporarily store the "before" values (eg. global_var := Rec;) and then just compare, using the recordref and fieldref variable types, any differences between the global variable record to Rec. I've used this quite often and it works well.

    I guess that would work also :-k , but it sounds quite complex . I have always done it by just the one line compare, but maybe I am just lazy and hate writing lots of lines of code. \:D/

    By the way this sometimes does not work if you have very large records, but thats pretty rare, you would need a lot of populated fields to overflow.
    David Singleton
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Yes, David, you are definataly lazy. :mrgreen:

    Cool tip BTW. =D>
  • David_SingletonDavid_Singleton Member Posts: 5,479
    Yes, David, you are definataly lazy. :mrgreen:

    Cool tip BTW. =D>

    Yeah Mark, I guess you are right, there are a ton of things I just do, and think "well surely everyone does it that way". But how do you remember them all.
    David Singleton
  • JohnConJohnCon Member Posts: 55
    Thanks I will try both options.
  • Alex_ChowAlex_Chow Member Posts: 5,063
    It'd be nice if there was a function to loop through the fields on a table.

    But I guess it's not that important...
  • David_SingletonDavid_Singleton Member Posts: 5,479
    JohnCon wrote:
    Thanks I will try both options.

    ](*,) ](*,) ](*,)


    deadlizard wrote:
    It'd be nice if there was a function to loop through the fields on a table.

    But I guess it's not that important...
    That's what RecRef is for.
    David Singleton
  • wonmowonmo Member Posts: 139
    FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
    IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
    {whatever action you want to do}
    END;
    END;

    This is how to compare the values of each field between 2 tables.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    wonmo wrote:
    FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
    IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
    {whatever action you want to do}
    END;
    END;

    This is how to compare the values of each field between 2 tables.

    OK, so it looks like Mark is right, I am just too lazy.

    Of course me and my silly idea of writing just one line of code when just as easily you can write five. Sorry next time I will make the effort to write more code.

    Not only that, but think of all the hardware suppliers that I am depriving of income by writing efficient code, rather than lots of lines that will sell more powerful hardware. Hey Mark, Dell must hate guys like us. #-o
    David Singleton
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    :mrgreen:

    True, I am having a discussion at this moment with a hosting company. They love to solve performance issues with more hardware, while I want to tune the database so we can use less hardware. ](*,)
  • David_CoxDavid_Cox Member Posts: 509
    wonmo wrote:
    FOR i := 1 TO recref_Original.FIELDCOUNT DO BEGIN
    IF recref_Original.FIELDINDEX(i).VALUE <> recref_New.FIELDINDEX(i).VALUE THEN BEGIN
    {whatever action you want to do}
    END;
    END;

    This is how to compare the values of each field between 2 tables.

    I have not used RecRef much, so if this sounds dumb, don't worry.
    So how would you assign say a modified Rec to recref_New ?
    Remembering that both record have the same key (RecRef)!

    We are not comparing Record1 to Record2, but Record1 to Record1 (Modified)

    If you use a GET or SET would it not retreive the Original from the database?

    Dave
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • wonmowonmo Member Posts: 139
    grec_Original := Rec;

    {do something}

    recref_Original.GETTABLE(grec_Original);
    recref_New.GETTABLE(Rec);

    You are now ready to compare field by field. I use this to log all changes done to a record. These changes (as text) get loaded into a BLOB field which can quickly be viewed with just a few lines of code and Notepad.
  • David_CoxDavid_Cox Member Posts: 509
    Thanks:
    I will try this, what I want is to allow users only to change a selection of fields, once an order reaches a particular status.

    I.E. If the Purchase Header has been authorised then don't allow the Line Quantity to be changed, but the Qty. to Receive can be changed, this should work fine.
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • wonmowonmo Member Posts: 139
    On the OnAfterGetRecord just add the code:

    CurrForm."Line Quantity".EDITABLE({Purchase Header has been authorised});

    And just repeat this line of code for any field you want to control edits on.
Sign In or Register to comment.