Strange behavior of temp record

ta5ta5 Member Posts: 1,164
Hello

I have a problem working with temporary records. The problem occurs as soon as I'm working on a copy of a temporary record. Of course this is just an example.
// create to records in temporary table
FOR iTemp := 1 TO 2 DO BEGIN
  Currency.Code := 'Code ' + FORMAT(iTemp);
  Currency.INSERT;
END;

// loop trough temporary records
IF Currency.FIND('-') THEN BEGIN
  REPEAT
    MESSAGE('loop on original temp record: %1',Currency.Code);
  UNTIL Currency.NEXT = 0;
END;


// make a copy of the temporary record, Currency2 is temporary too
Currency2 := Currency;

// loop through copy of temporary record
// DOES NOT WORK!
IF Currency2.FIND('-') THEN BEGIN
  REPEAT
    MESSAGE('loop on copy of temp record: %1',Currency2.Code);
  UNTIL Currency2.NEXT = 0;
END;

Please note, the 2nd loop does not work, as Currency2.find('-') is false.
Any ideas? I think, I'm missing something ](*,)

Thanks a lot
Thomas

Answers

  • kapamaroukapamarou Member Posts: 1,152
    // make a copy of the temporary record, Currency2 is temporary too
    Currency2 := Currency;

    This will not copy your records into Currency2.

    You'll need an INSERT...
  • ta5ta5 Member Posts: 1,164
    Thanks, but imho it works when currency and currency2 are not temporary. For testing this I also dont use the 2 inserts at the beginning of the codeunit.
    What do you think?
  • kapamaroukapamarou Member Posts: 1,152
    Think of := as a reference to a record.

    The find('-') works in Normal tables because the entries exist. When working with temporary tables they don't exist. you need a loop to copy all the records from one variable to the other...
  • ta5ta5 Member Posts: 1,164
    Ok thanks.
    The problem is the following. My code example was just for demonstration purposes. I actually try to pass a record variable to another object (form or report). This is a bit difficult to show in an example, but same problem there. Working with non-temporary vars works just fine, working with temporary vars don't.

    Any ideas appreciated
    Thomas
  • kapamaroukapamarou Member Posts: 1,152
    from a quick test I think what you want to achieve can be done using the command

    Rec.COPY(FromRecord[,ShareTable]) which is available (with the extra parameter) only in version 6...

    In prior versions you will need to pass the parameter as a VAR and then loop through the records and add them in your Temporary Global Variable...
  • kapamaroukapamarou Member Posts: 1,152
    kapamarou wrote:
    only in version 6...

    I mean 2009... :oops:
  • DenSterDenSter Member Posts: 8,304
    ta5 wrote:
    Thanks, but imho it works when currency and currency2 are not temporary.
    A temporary record variable is just empty memory that is structured like the table you base the variable on. Every time you use a new temp variable, it starts out empty. You have to fill the temp table with the temporary records. Because currency and currency2 are two different variables, they point to different sections of the memory. They are two dofferent entities.

    If it's not a temp record it points to the actual table. You will see all records for every non-temporary record variable, because they all point to the same table, you are looking at actual physical records in the physical table. The two variables are two different objects in memory, but they point at the same thing.

    If you want to fill a temp record in one object and send the whole thing into another, you'll have to pass it by reference (i.e. with the VAR checkbox ticked in the parameter screen). Also make sure that the parameter itself is temporary.
  • ta5ta5 Member Posts: 1,164
    kapamarou wrote:
    In prior versions you will need to pass the parameter as a VAR and then loop through the records and add them in your Temporary Global Variable...

    Thanks, this works, the code now loops through the parameter in the remote function (passed by reference). Then another temporary variable of the same type is filled with the values. Maybe not the sleekest way, but with only a few records we need it for its ok.

    Thanks also to Daniel for his explanations!

    Thomas
  • DenSterDenSter Member Posts: 8,304
    Always happy to help :mrgreen: good to hear that you were able to make it work.
  • ta5ta5 Member Posts: 1,164
    And once more:
    Mibuso.com is THE place to get infos like that!!
  • kapamaroukapamarou Member Posts: 1,152
    Happy we could help...
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,499
    [The use of [SOLVED] in the Topic Title is no longer supported. Please edit the first message in the thread and use the field Attribute (below the Subject-field) to put a green checkmark next to the Topic Title]
Sign In or Register to comment.