The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Delphi Programming
|
TByteRec Conversion
Discuss TByteRec Conversion in the Delphi Programming forum on Dev Shed. TByteRec Conversion Delphi Programming forum discussing Delphi related topics including Kylix, C++ Builder, and more. Delphi is a high-performance language, originally based on the PASCAL language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 26th, 2012, 07:58 PM
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 6
Time spent in forums: 1 h 13 m 9 sec
Reputation 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
|

June 26th, 2012, 08:50 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
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
|

June 28th, 2012, 04:43 PM
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 6
Time spent in forums: 1 h 13 m 9 sec
Reputation 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
|

July 1st, 2012, 10:40 AM
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 6
Time spent in forums: 1 h 13 m 9 sec
Reputation 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
|

July 1st, 2012, 12:29 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
Quote: | 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
|

July 2nd, 2012, 06:33 PM
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 6
Time spent in forums: 1 h 13 m 9 sec
Reputation 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/product...ssions_xml.html .
Let me know if I am on the right track.
Thanks!!
|

July 2nd, 2012, 07:04 PM
|
|
Contributing User
|
|
Join Date: Jan 2006
Location: Carlsbad, CA
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|