Using DUPLICATE function

Dmitry_ChadaevDmitry_Chadaev Member Posts: 52
Hello guys,

I am a little confused about a certain situation when I use temporary RecRef and DUPLICATE function.

I have a task - I need to perform some modifications on records temporarily. So I create a temporary buffer - move some records there and perform modifications on records in this buffer. The thing is that there might be thousands of records I need to move in this buffer, so I thought I could make it by using temporary RecRefs...

Here is my example:
ContRecRef.OPEN(5050);
ContRecRef.SETVIEW('WHERE(Salesperson Code = CONST(JR))');

ContRecRefTemp.OPEN(5050,TRUE);
MESSAGE(FORMAT(ContRecRefTemp.COUNT)); // Returns '0' - ok

ContRecRefTemp := ContRecRef.DUPLICATE;
MESSAGE(FORMAT(ContRecRefTemp.COUNT)); // Returns '120' - ok

IF ContRecRefTemp.FINDSET(TRUE) THEN
  REPEAT
    FldRef := ContRecRefTemp.FIELD(10); //Telex No.
    FldRef.VALUE := 'BlaBlaBla';
    ContRecRefTemp.MODIFY;
  UNTIL ContRecRefTemp.NEXT = 0;

IF ContRecRef.FINDFIRST THEN BEGIN
  FldRef := ContRecRef.FIELD(10);
  MESSAGE(FORMAT(FldRef.VALUE)); // Returns 'BlaBlaBla' - not ok
END;

It seems that when I use DUPLICATE - it disregards the fact that the destination RecRef is temporary...

The OnLine help says:
DUPLICATE (RecordRef)

Comments
The recordref that is returned refers to a table with the exact same values, filters, current keys and marks as the original table. However, any changes that you make to the duplicate will not be reflected in the original. (This is different than assigning one recordref to another recordref, where they continue to refer to the same table and where changes made to one are reflected in the other.)

Why then the changes I made on ContRecRefTemp appear on ContRecRef?

Is it something I misunderstood about the concept of DUPLICATE or temporary RecRefs? Will appreciate your hints :)
Best regards,
Dmitry

Comments

  • kinekine Member Posts: 12,562
    However, any changes that you make to the duplicate will not be reflected in the original.
    Means, that the changes are not seen in the original record without refreshing. That is all. It is not about the table or about that the data are not store etc...

    Because if you do only assignment without DUPLICATE, and if you change some data in the record, both recref will have the data changed. The RecRef are still "pointing" to same record in memory. But if you do DUPLICATE, the object in memory is duplicated and the recref points to another area of memory...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.