Recref/fieldref Loop

BeliasBelias Member Posts: 2,998
CLEAR(RecRef);
CLEAR(FieldRef);
CLEAR(TBField);
RecRef.OPEN(INTTableNo);
RecRefHT.OPEN(INTHistTableNo);
TBField.SETRANGE(TableNo,INTHistTableNo);
IF RecRef.FINDSET(FALSE,FALSE) THEN BEGIN
  REPEAT
    RecRefHT.INIT;
    TFFirstLoop := TRUE;
    IF TBField.FINDSET(FALSE,FALSE) THEN BEGIN
      REPEAT
        FieldRef := RecRef.FIELD(TBField."No.");
        FieldRefHT := RecRefHT.FIELD(TBField."No.");
        IF NOT CONFIRM ('a' + FORMAT(FieldRefHT.VALUE) + 'b' + FORMAT(FieldRef.VALUE)) THEN ERROR('a');
        FieldRefHT.VALUE := FieldRef.VALUE;
        TFFirstLoop := FALSE;
        IF TFFirstLoop THEN BEGIN
          RecRefHT.INSERT;
        END ELSE
          RecRefHT.MODIFY;
      UNTIL TBField.NEXT = 0;
    END;
  UNTIL RecRef.NEXT = 0;
END;

it keeps giving me this error:
Identification fields and values:

List Type='Cylinder Rental List',Code='CR 1',Starting Date='',Package Code='',Business Code=''

Debugging the code, it seems that stops after copying the second field...
i'm trying to copy all fields from one rref to another (as rref.transferfields does not exist :evil: )

thanks in advance
-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog

Answers

  • krikikriki Member, Moderator Posts: 9,110
    I think the primary key of your tables exists of multiple fields. So you INSERT the record after filling up the first primary-key field with the others still blank.
    Then you fill up the second primary-key field and do a MODIFY. But the record doesn't exist because you saved it the previous loop.
    So copy first ALL fields to your history-record and then do an INSERT. (if your primary key existed of only 1 field, it would work, but VERY slow because you do a MODIFY after each field. Now I don't do MODIFY anymore but only an INSERT.

    CLEAR(RecRef);
    CLEAR(FieldRef);
    CLEAR(TBField);
    
    RecRef.OPEN(INTTableNo);
    RecRefHT.OPEN(INTHistTableNo);
    
    IF RecRef.FINDSET(FALSE,FALSE) THEN BEGIN
      REPEAT
        RecRefHT.INIT;
        
        TBField.RESET;
        TBField.SETRANGE(TableNo,INTHistTableNo);
        IF TBField.FINDSET(FALSE,FALSE) THEN BEGIN
          REPEAT
            FieldRef := RecRef.FIELD(TBField."No.");
            FieldRefHT := RecRefHT.FIELD(TBField."No.");
            FieldRefHT.VALUE := FieldRef.VALUE;
          UNTIL TBField.NEXT = 0;
        
        RecRefHT.INSERT;
      UNTIL RecRef.NEXT = 0;
    END;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • BeliasBelias Member Posts: 2,998
    :shock:
    you're perfectly right...and believe or not, the code you wrote was the first version of my program...and it didn't work!!

    i tried to rewrite it and it worked! :shock:

    maybe i putted this
    RecRefHT.INSERT;
    
    IN the loop without noticing it ](*,) ](*,) ](*,) ](*,)
    thank you!
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.