copy a VAR parameter of a function to a global var

boubounasboubounas Member Posts: 17
Hi there,

I have the following code:
SetMyRecord(VAR MyRec : Record)
MyGlobalRec.COPY(MyRec);
//or even MyGlobalRec := MyRec;

My parameter has MyRec.COUNT equal to 3. After I copy it to MyGlobalRec with either of the above ways then MyGlobalRec.COUNT is equal to 1. Can someone explaing why please? And how can I copy all 3 records to my global variable?

Note that I get the same results if I try to copy MyRec into Rec.

Thanks in advance.
"After 5 billion years man said: Let there be God"

Answers

  • ara3nara3n Member Posts: 9,256
    I haven't tried it yet but try to loop through MyRec and
    insert them into MyGlobalRec.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ayhan06ayhan06 Member Posts: 210
    MyGlobalRec := MyRec;
    
    this code fills the fields in the MyGlobalRec with the values in the MyRec. this code does not change the record count of MyGlobalRec. COUNT is calculated according to filters.
    MyGlobalRec.COPY(MyRec);
    
    this must work.after this line, MyGlobalRec must have 3 records.. can you post the all of your code please? i want to see how you filtered the record,when you called SetMyRecord function, etc..
    SetMyRecord(VAR MyRec : Record) 
    MESSAGE(FORMAT(MyRec.COUNT));
    MESSAGE(FORMAT(MyGlobaRec.COUNT));
    MyGlobalRec.COPY(MyRec); 
    MESSAGE(FORMAT(MyGlobaRec.COUNT));
    
    also, can you check the messages in the shown above?
  • KrokceKrokce Member Posts: 1
    Your MyRec record set probably includes MARKED records which are not copied neither by COPY nor by COPYFILTERS.
    One way to solve the problem is cycling through all (MARKED) records and create a filter string based on primary key...

    e.g.
    MyGlobalRec.RESET;
    
    MyRec.FIND('-');
    REPEAT
      IF STRLEN(strTableFilter) > 0 THEN strTableFilter := strTableFilter + '|' ;
      strTableFilter := strTableFilter + FORMAT(MyRec.RecordID);
    UNTIL MyRec.NEXT() = 0;
    
    MyGlobalRec.SETFILTER(RecordID, strTableFilter);
    

    Hope this helps...
  • boubounasboubounas Member Posts: 17
    ayhan06 wrote:
    i want to see how you filtered the record,when you called SetMyRecord function, etc..

    also, can you check the messages in the shown above?

    Ayhan, thanks for your reply.
    MyRec does NOT have any filters at all. And just to make sure, I do a MyRec.RESET just before I call the SetMyRecord function.

    Here is what you asked:
    SetMyRecord(VAR MyRec : Record) 
    MESSAGE(FORMAT(MyRec.COUNT));      // Message here is: 3
    MESSAGE(FORMAT(MyGlobaRec.COUNT));// Message here is: 0
    MyGlobalRec.COPY(MyRec); 
    MESSAGE(FORMAT(MyGlobaRec.COUNT));// Message here is: 1
    
    "After 5 billion years man said: Let there be God"
  • boubounasboubounas Member Posts: 17
    Krokce wrote:
    Your MyRec record set probably includes MARKED records which are not copied neither by COPY nor by COPYFILTERS.

    Hi Krokce, thanks for your reply.
    I did a MyRec.MARKED just before I call the SetMyRecord function and returned FALSE which means that it doesnt contain any marked records.

    Can someone try it plz, its quick.
    "After 5 billion years man said: Let there be God"
  • boubounasboubounas Member Posts: 17
    I found the problem and the solution. The problem was that MyGlobalRec and MyRec (the parameter to the function) were temporary, meaning that the table is temporary and so it doesnt have any entries. So when MyGlobalRec even after the copy function is points to an empty table.

    The solution is looping through and inserting the entries from MyRec to MyGlobalRec:

    SetMyRecord(VAR MyRec : Record Item)
    IF MyRec.FIND('-') THEN
      REPEAT
        MyglobalRec := MyRec;  // not necessary to copy with filters for the 
    insert
        MyglobalRec.INSERT;
      UNTIL MyRec.NEXT = 0;
    ...
    
    "After 5 billion years man said: Let there be God"
Sign In or Register to comment.