#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0

    TByteRec Conversion


    Hello again,
    I came across the code below and I am trying to convert to VB.Net. I have never seen the ".na", ".nd", or the ".nv"

    Can someone tell me what this code is doing and how to convert it to VB.Net?

    Code:
    type
      TByteRec = record
      acc, nd, nv, na: Byte;
    end;
    
    var
      Buf: String;
      i, iacc, k, n: Integer;
    
    iacc := qPFTREP_CODE.AsInteger;
    i := TByteRec(iacc).na;              // n acceptable
    Buf := Buf + IntToStr(i) + ',';
    i := TByteRec(iacc).nd;              // n deleted
    Buf := Buf + IntToStr(i) + ',';
    k := TByteRec(iacc).nv;           // compute nvext
    Thanks for your help in advance!!
    Eddi Rae
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    TByteRec is declared as a record containing four individual bytes.
    In this code it gives you a convenient way to access the individual byes that comprise the integer iacc.

    BTW: Buf needs to be initialized somewhere. Either to your starting value or to an empty string. Local variables are not magically initialized by the compiler the way object fields are initialized during creation. However, as you are converting away from Delphi this is probably irrelevant.

    Clive
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0
    Thanks for the explanation.

    Yes. Buf is being initialized. This is just the part of the code that I needed an explanation on.

    Thanks again!!
    Eddi Rae
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0
    Clive,
    I was noticing that the .na, .nd and .nv are not defined.

    Since I am converting to VB.Net, how would these correlate to the different sections on an integer.

    I am needing to come up with the same values.

    Thanks in advance
    Eddi Rae
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    I was noticing that the .na, .nd and .nv are not defined.
    Take another look at the record definition.
    Each one is defined as Byte.
    Their names are simply field names assigned for the benefit of the programmer,
    they have no significance to the compiler beyond identifying which Byte is being referenced.

    They could just as easily have been named a,b,c,d (as I have done in my own code).
    I have to assume that .na, .nd and .nv have some human meaning to the task at hand.

    Hope this makes sense.

    WARNING: When splitting an integer into its individual bytes you need to be aware of any big endian / little endian issues.

    Clive
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0
    type
    TByteRec = record
    acc, nd, nv, na: Byte;
    end;

    So in this instance, I am breaking the TByteRec into four bytes.
    acc is first byte, nd is second byte, nv is third byte and na is fourth byte.

    Is my understanding correct?

    I found this link that explains the use of the TByteRec
    http://docs.embarcadero.com/products...sions_xml.html .

    Let me know if I am on the right track.

    Thanks!!
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Yes. You are on the right track.

    Of course, the TByteRec you referenced in the URL is a two byte record suitable for handling a Word.
    Your TByteRec is a four byte record capable of handling a 32-bit integer.

    I'm sure you realized that.

IMN logo majestic logo threadwatch logo seochat tools logo