Options

changing the tablesource of a record-var?

redStriperedStripe Member Posts: 83
Hello,
I got a new problem...
I have a table with a col called "table.nr", in each line is different value
e.g. 23, 18 or 65
Now I want write a function that opens, line after line, the table ...
Is it possible to change the sourcetable of recordvar during the execution?

redStripe

Answers

  • Options
    Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    You need to use a variable of type RecordRef. A record-variable can not be changed at run-time, to point to a different table.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • Options
    redStriperedStripe Member Posts: 83
    Hi Luc,
    thanks for your tip. if i use recordref and fieldref like that
      recordRef.OPEN("Table No.");
      fieldRef := recordRef.FIELD("Field No.");
    

    how can i get the value of the field?

    redStripe
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Have you tried using
    FldRef.VALUE
    
  • Options
    redStriperedStripe Member Posts: 83
    FieldRef.VALUE
    

    doesn't work ...
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    :? It should...

    What error message do you get?

    Or is it a flowfield?
  • Options
    redStriperedStripe Member Posts: 83
    I get no error-message. VALUE is just empty :(
      RecordRef.OPEN(Record."Table No.");
      FieldRef := RecordRef.FIELD(Record."Field No.");
      MESSAGE('TabNr.: %1 
                      TabName: %2 
                      FieldNr.: %3 
                      FieldName.: %4 
                      FieldValue: %5',
                      tmpTable.NUMBER, 
                      tmpTable.NAME, 
                      tmpField.NUMBER, 
                      tmpField.NAME, 
                      tmpField.VALUE);
    

    I get every Information but Value is empty.
    Did I mistake?

    redStripe
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    The code you are posting is a bit confusing :?

    What is the value of Record."Field No." ?

    Why have you programmed a message with an other variable than the FieldRef?

    FieldRef.VALUE returns a Variant with the value.

    If it is a flowfield you should use calcfields first.
  • Options
    redStriperedStripe Member Posts: 83
    sorry marc to confuse you ;)
    i edit the code for the forum and forget to rename my variable.
    here is the code again:
    RecordRef.OPEN(Record."Table No."); 
      FieldRef := RecordRef.FIELD(Record."Field No."); 
      MESSAGE('TabNr.: %1 
                      TabName: %2 
                      FieldNr.: %3 
                      FieldName.: %4 
                      FieldValue: %5', 
                      RecordRef.NUMBER, 
                      RecordRef.NAME, 
                      FieldRef.NUMBER, 
                      FieldRef.NAME, 
                      FieldRef.VALUE);
    

    >What is the value of Record."Field No." ?
    The number of the field, which I want the value. e.g. 5

    btw it is no flowfield.

    redStripe
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Problem is that you have not defined a record in the RecRef.

    You should eitger do a get/find or pass a record to the recordref.
    RecRef.GET
    
    RecRef.FIND
    
    
  • Options
    redStriperedStripe Member Posts: 83
    I have a record var ... i just renamed it, because of better understanding ..
    and I also do a find a few lines above.

    here ist the original code:
    tmpTable = RecordRef
    tmpField = FieldRef
    Check_Value_Field_rec.INIT;
    Check_Value_Field_rec.FIND('-');
    REPEAT
      tmpTable.OPEN(Check_Value_Field_rec."Table No.");
      tmpField := tmpTable.FIELD(Check_Value_Field_rec."Field No.");
      MESSAGE('TabNr.: %1 TabName: %2 FieldNr.: %3 FieldName.: %4 FieldValue: %5'
              ,tmpTable.NUMBER, tmpTable.NAME, tmpField.NUMBER, tmpField.NAME, tmpField.VALUE);
    UNTIL Check_Value_Field_rec.NEXT = 0;
    

    the problem ist that I get every information of the table and the field,
    but not the tmpField.VALUE
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Ok. This is in your code:
    Check_Value_Field_rec.INIT; 
    Check_Value_Field_rec.FIND('-'); 
    REPEAT 
      tmpTable.OPEN(Check_Value_Field_rec."Table No."); 
      if tmpTable.FIND('-') then repeat
        tmpField := tmpTable.FIELD(Check_Value_Field_rec."Field No."); 
    
    MESSAGE('TabNr.: %1 TabName: %2 FieldNr.: %3 FieldName.: %4 FieldValue: %5' 
              ,tmpTable.NUMBER, tmpTable.NAME, tmpField.NUMBER, tmpField.NAME, tmpField.VALUE); 
      Until tmpTable.NEXT = 0;
    
    UNTIL Check_Value_Field_rec.NEXT = 0; 
    

    Without a find or get it is the same as defining a record variable and message a fieldvariable without a get or find.
  • Options
    redStriperedStripe Member Posts: 83
    thanks a lot ... now it works :)
  • Options
    Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
Sign In or Register to comment.