Pass a rec to a temporary rec

BeliasBelias Member Posts: 2,998
i am currently developing a function to do some checks...these checks are done in a function (not created by me) which takes a TableTemp as parameter (declared as temporary) - BYVAR.
this function does not does not do any InsModDel instrunctions, so, i was wondering if can i pass a non-temporary record variable to this function...
Moreover, (this is not my case) what would happen if some field is changed within the function, and then after the function, i do a modify on the original table(which is not temporary)? -i think the table is modified according to the modified field, but i'm not sure-
I hope to be clear, and I hope there's not such a question in mibuso because i don't know what to search :whistle:
thanks in advance
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog

Answers

  • kapamaroukapamarou Member Posts: 1,152
    Belias wrote:
    i am currently developing a function to do some checks...these checks are done in a function (not created by me) which takes a TableTemp as parameter (declared as temporary) - BYVAR.

    You mean that the Temporary property is set on the parameter? I don't think it matters since you are passing ByVAR. If your original record that was passed as a parameter was declared as temp then ok. I think in this case if you call modify it will affect the original record. And you can pass it even if it isn't temporary. Have you tried an example to see the result?


    P.S. I think in Version 2009 there is a nice change in the Rec.COPY function. Maybe this helps you ...
    (From C/Side Reference)...

    Copies a record from a C/SIDE table. All filters, marks, and keys are included in the copy.
    Record.COPY(FromRecord [, ShareTable])
    Parameters
    Record
    Type: Record
    The record where the copy will be placed.
    FromRecord
    Type: Record
    The record that you want to copy.
    ShareTable
    Type: Boolean
    Specifies whether the function creates a copy of the record or creates a reference to a temporary record.
    If FromRecord and Record are both temporary and ShareTable is true, then the COPY function does not create a new copy of the record. Instead, the COPY function causes Record to reference the same table as FromRecord.
    The default value is false. If you specify false, all records are copied to Record from FromRecord.
  • BeliasBelias Member Posts: 2,998
    excuse me, version 4.01...anyway, i don't have time to make an example, as i'm not modifying the table, anyway...i was wondering if someone knew this...
    didn't know about rec.copy new parameter...it is like doing
    mytemp := myreal;
    mytemp.copyfilters(myreal);
    
    isn't it?
    Thank you
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • garakgarak Member Posts: 3,263
    if the Paramerte is temp. and the sended table isn't it, and its Call by Reference (VAR), then the modification in your function will modify the real rec!
    So, for example you send the Item rec to you function. There you change the Description of Item 1000 from "Colour, blue" to "My colored bike", then in table 27 the item 1000 has the description "My colored bike".

    This is the reason for the VAR flag (Call by reference). You work not on a copy of the rec, you work on the rec self.
    In call-by-reference evaluation, a function receives an implicit reference to the argument, rather than a copy of its value. And this is here you real rec.

    Regards.
    Do you make it right, it works too!
  • BeliasBelias Member Posts: 2,998
    So, if the record will be modified both if i run MODIFY "in" the function or if i run MODIFY after coming back to the caller trigger/function. Thank you!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.