Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 26th, 2012, 07:58 PM
EddiRae EddiRae is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 6 EddiRae User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old June 26th, 2012, 08:50 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
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

Reply With Quote
  #3  
Old June 28th, 2012, 04:43 PM
EddiRae EddiRae is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 6 EddiRae User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old July 1st, 2012, 10:40 AM
EddiRae EddiRae is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 6 EddiRae User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old July 1st, 2012, 12:29 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
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

Reply With Quote
  #6  
Old July 2nd, 2012, 06:33 PM
EddiRae EddiRae is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2009
Posts: 6 EddiRae User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!!

Reply With Quote
  #7  
Old July 2nd, 2012, 07:04 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > TByteRec Conversion

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap