Array of records!

abartonicekabartonicek Member Posts: 162
edited 2005-11-03 in Navision Attain
Table: OurTable
Field name....Type
No................Code
Value............Int
...

On Card form we have:
Variable name..........DataType..Subtype.....Dimensions property
OurArrayVariable......Record.....OurTable....3
OurVariable..............Record.....OurTable.....<Undefined>

What happens with the table record that variable points to when we do this:
SETRANGE(No);
OurArrayVariable[1].Value := 20;
OurArrayVariable[2].Value := 10;

What are the values of:

OurArrayVariable[3].Value and
OurVariable.Value


Hope you know what I mean :)
Better to be critical then self-critical :)

Comments

  • DenSterDenSter Member Posts: 8,307
    Whatever you do to one variable has no effect on another variable. If you do:
    x := some value;
    
    then everything else does not change.

    The same happens in an array. If you do:
    x[i] := some value;
    
    then x[i+n] is not affected.
  • abartonicekabartonicek Member Posts: 162
    I know that but...
    The array thing confuses me.

    What if I do this:

    OurVariable.Value := 50;

    The field "Value" in OurTable changes it's value to 50 - Right?

    But what does:
    OurArrayVariable[1].Value := 25;
    Better to be critical then self-critical :)
  • DenSterDenSter Member Posts: 8,307
    That changes the Value attribute to 25 of the element with index value 1 in your array.

    Do you know what an array is?
  • abartonicekabartonicek Member Posts: 162
    Yes!

    What I don't know is the relation between that array elements and table field Value.

    To put it this way:

    OurVariable.Value := 50; changes the field "Value" in "OurTable"

    Does
    OurArrayVariable[1].Value := 25; changes anything in "OurTable"
    Better to be critical then self-critical :)
  • DenSterDenSter Member Posts: 8,307
    The variable does not change anything in the database until you tell it to. Until then, it is just a piece of memory.

    OurVariable.Value := 50; does NOT change the Value field in our table, it only changes the value of the field in your variable. To save the value to the database, you will have to do OurVariable.MODIFY.

    If you do OurVariable.Value := 50; and the MODIFY, and you do OurArrayVariable[1].Value := 25 and then MODIFY you will get an error.

    You should create a little test form and play around with this. It is pretty straightforward.
  • kinekine Member Posts: 12,562
    Look at this in this way: Each Record Variable is Finger (Finger = cursor) pointing on some record in your table and the values from that record are copied on this "finger". It means - each array element is one finger, each finger can point to another record (or on same record). But each finger has own copy of the record - it is why when you change the value of one field on one "finger", others are not affected.

    Record 1  - Array[1]
    Record 2  \ Array[2]
            / Array[3]
    Record 3  - Array[4]
            \Array[5]
    

    We have 5 cursors to same table. 1 and 2 are set to record 1, 3..5 are set to record 3. If you do
      Array[3].Field1 := Val1;
      Array[5].Field1 := Val2;
      Array[3].Modify;
      Array[5].FIND('=');
    
    In the Record 3 in field1 will be Val1. Because each Cursor is copy of the record, and the changes are transfered only with MODIFY (chages from cursor to table) or FIND and GET (read the data from table into cursor). And after the FIND the Val1 will be in Array[5].Field1 too...

    etc. etc.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • abartonicekabartonicek Member Posts: 162
    OK

    Sorry for beeing boring!

    I mixed something, I was looking Form 402 and how (or why) they use arrays of records.
    Better to be critical then self-critical :)
  • abartonicekabartonicek Member Posts: 162
    In form 402 they use arrays of record to minimize the code or something else?

    They use "one dimension per tab".
    Better to be critical then self-critical :)
  • DenSterDenSter Member Posts: 8,307
    In that form, you can see the statistics of a sales order. If you would open a sales order, turn on the debugger and hit F9, you can step through the code and see what happens. The TotalSalesLines variable does not write anything to the database, it is merely used to store statistical information. If I had designed this form, I would have created three different variables instead of an array of variables, and given them meaningful names, like TotalOrderLines, TotalInvoiceLines and TotalShippingLines or something like that.

    It is nothing more than a data structure to store information that is displayed on the form.
  • abartonicekabartonicek Member Posts: 162
    Thanx all, for your help & time!
    Better to be critical then self-critical :)
Sign In or Register to comment.