<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Moving from byteint array to record' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Moving from byteint array to record' posted on the 'Pascal' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Thu, 20 Jun 2013 04:47:56 -0700</pubDate>
    <lastBuildDate>Thu, 20 Jun 2013 04:47:56 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392258/moving-from-byteint-array-to-record/</link>
      <description>Sorry have not dealt in Pascal in quite some time&lt;br /&gt;
so any help appreciated.&lt;br /&gt;
&lt;strong&gt;&lt;br /&gt;
Here is my scenerio:&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
bulkrec = record&lt;br /&gt;
  job          : LongInt;    &lt;br /&gt;
  relation     : packed array [1..8] of char;&lt;br /&gt;
  reclen       : LongInt;&lt;br /&gt;
  bulk : array [1.. 1000] of ByteInt;&lt;br /&gt;
&lt;br /&gt;
pbulkrec = ^bulkrec;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;and then I have another record like:&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
custfile = record&lt;br /&gt;
   custnum  : ShortNat;&lt;br /&gt;
     group  : ShortNat;&lt;br /&gt;
      name  : packed array [1..20] of char;&lt;br /&gt;
      flag1 : boolean;&lt;br /&gt;
      flag2 : boolean;&lt;br /&gt;
      flag3 : boolean;&lt;br /&gt;
      flag4 : boolean;&lt;br /&gt;
end;&lt;br /&gt;
&lt;br /&gt;
pcustfile = ^custfile;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Problem then is that the bulkrec.bulk field actually&lt;br /&gt;
holds the custfile data and I want to move it from that&lt;br /&gt;
array into custfile record... i.e.&lt;br /&gt;
&lt;br /&gt;
custnum is a 2 byte field so the concatenation of  &lt;br /&gt;
bulk[1] and bulk[2] holds its value.&lt;br /&gt;
&lt;br /&gt;
group also is a 2 byte field so the concatenation of&lt;br /&gt;
bulk[3] and bulk[4] holds its value.&lt;br /&gt;
&lt;br /&gt;
name is 20 byte field and thus&lt;br /&gt;
bulk[5] thru bulk[24] hold its value.&lt;br /&gt;
&lt;br /&gt;
flags1-4 hold 1 byte a piece &lt;br /&gt;
bulk[25] to bulk[28] respectively.&lt;br /&gt;
&lt;br /&gt;
How do I make this assignment from the bulkrec.bulk&lt;br /&gt;
variable to the custfile record???&lt;br /&gt;
&lt;br /&gt;
Any help appreciated.&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392258/moving-from-byteint-array-to-record/</guid>
      <pubDate>Fri, 12 Jun 2009 14:59:06 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392259/re-moving-from-byteint-array-to-record/#392259</link>
      <description>What is a ByteInt?  What is a ShortNat?&lt;br /&gt;
&lt;br /&gt;
Neither of these terms is part of modern Pascal.&lt;br /&gt;
&lt;br /&gt;
I'm guessing that&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
Type
   ByteInt = 0 .. 255 ;  { i.e., type Byte }
   ShortNat = -128 .. 127 ;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
By the way the word &lt;strong&gt;packed&lt;/strong&gt; is obsolete.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392259/re-moving-from-byteint-array-to-record/#392259</guid>
      <pubDate>Fri, 12 Jun 2009 17:24:29 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392260/re-moving-from-byteint-array-to-record/#392260</link>
      <description>Not using modern Pascal.&lt;br /&gt;
&lt;br /&gt;
ShortNat &lt;br /&gt;
Format of type shortnat                        &lt;br /&gt;
  Total size in bytes:     2&lt;br /&gt;
  Type is packed&lt;br /&gt;
range (type:integer) from 0 to 32767&lt;br /&gt;
&lt;br /&gt;
Format of type byteint                         &lt;br /&gt;
  Total size in bytes:     1&lt;br /&gt;
  Type is packed&lt;br /&gt;
range (type:integer) from -128 to 127&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392260/re-moving-from-byteint-array-to-record/#392260</guid>
      <pubDate>Fri, 12 Jun 2009 17:57:16 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392265/re-moving-from-byteint-array-to-record/#392265</link>
      <description>&lt;pre class="sourcecode"&gt;
: bulkrec = record
:   job          : LongInt;    
:   relation     : packed array [1..8] of char;
:   reclen       : LongInt;
:   bulk : array [1.. 1000] of ByteInt;
: 
: pbulkrec = ^bulkrec;
&lt;/pre&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;strong&gt;and then I have another record like:&lt;/strong&gt;&lt;br /&gt;
: &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
: custfile = record
:    custnum  : ShortNat;
:      group  : ShortNat;
:       name  : packed array [1..20] of char;
:       flag1 : boolean;
:       flag2 : boolean;
:       flag3 : boolean;
:       flag4 : boolean;
: end;
: 
: pcustfile = ^custfile;
&lt;/pre&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: Problem then is that the bulkrec.bulk field actually&lt;br /&gt;
: holds the custfile data and I want to move it from that&lt;br /&gt;
: array into custfile record... i.e.&lt;br /&gt;
: &lt;br /&gt;
: custnum is a 2 byte field so the concatenation of  &lt;br /&gt;
: bulk[1] and bulk[2] holds its value.&lt;br /&gt;
: &lt;br /&gt;
: group also is a 2 byte field so the concatenation of&lt;br /&gt;
: bulk[3] and bulk[4] holds its value.&lt;br /&gt;
: &lt;br /&gt;
: name is 20 byte field and thus&lt;br /&gt;
: bulk[5] thru bulk[24] hold its value.&lt;br /&gt;
:&lt;br /&gt;
: flags1-4 hold 1 byte a piece &lt;br /&gt;
: bulk[25] to bulk[28] respectively.&lt;br /&gt;
: &lt;br /&gt;
: How do I make this assignment from the bulkrec.bulk&lt;br /&gt;
: variable to the custfile record???&lt;br /&gt;
: &lt;br /&gt;
: Any help appreciated.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The first problem I see is your declarations&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   pbulkrec  : ^bulkrec;
   pcustfile : ^custfile;
&lt;/pre&gt;&lt;br /&gt;
where you declare &lt;strong&gt;pbulkrec&lt;/strong&gt; and &lt;strong&gt;pcustfile&lt;/strong&gt; as pointers.  The "problem" is that having to reference and de-reference the adds to the complexity and gets in the way of addressing the other issues.  I have not idea why you declare these as pointers instead of variables, but I'm going to address your other issues in terms of this declaration:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   pbulkrec  : bulkrec;
   pcustfile : custfile;
&lt;/pre&gt;&lt;br /&gt;
If you really need these to be pointers I'll leave it to you to make that adjustment.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;br /&gt;
: custnum is a 2 byte field so the concatenation of  &lt;br /&gt;
: bulk[1] and bulk[2] holds its value.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
I'm assuming that the definition of &lt;strong&gt;BulkRec&lt;/strong&gt; is being forced upon you by some existing software or data.  If so then the method of "concatenation" is ambiguous and we have to guess how the original programmer did it.  The simplest would be&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   with pbulkrec do
      with pcustfile do
         CustNum := 128*Bulk[1] + Bulk[2] ; 
&lt;/pre&gt;&lt;br /&gt;
This assumes that &lt;strong&gt;Bulk[1]&lt;/strong&gt; is the most significant byte, but it could be that &lt;strong&gt;Bulk[2]&lt;/strong&gt; is the MSB.&lt;br /&gt;
&lt;br /&gt;
However, &lt;strong&gt;Bulk&lt;/strong&gt; is signed and &lt;strong&gt;CustNum&lt;/strong&gt; is unsigned.  I think this is more likely:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   with pbulkrec do
      with pcustfile do
         CustNum := (256*(Bulk[1] + 128) MOD 32768) + (Bulk[2] + 128 ; 
&lt;/pre&gt;&lt;br /&gt;
Adding 128 to each &lt;strong&gt;Bulk&lt;/strong&gt; element shifts it into positive territory, and the MOD operator keeps &lt;strong&gt;CustNum&lt;/strong&gt; in range.  Of course this assumes that the original programmer took this same approach.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;br /&gt;
: name is 20 byte field and thus&lt;br /&gt;
: bulk[5] thru bulk[24] hold its value.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   for i := 1 to 20 do
      name[i] := bulk[i + 4] ;  &lt;span style="color: Red;"&gt;{ there may be problems with pack and unpack }&lt;/span&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;br /&gt;
: flags1-4 hold 1 byte a piece &lt;br /&gt;
: bulk[25] to bulk[28] respectively.&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
   flag1 := (bulk[25] = 0) ; &lt;span style="color: Red;"&gt;{ assume zero means FALSE }&lt;/span&gt;
   flag2 := (bulk[26] = 0) ; &lt;span style="color: Red;"&gt;{ any else means TRUE }&lt;/span&gt;
   flag3 := (bulk[27] = 0) ;
   flag4 := (bulk[28] = 0) ;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
What do &lt;strong&gt;Bulk[29] .. Bulk[1000]&lt;/strong&gt; hold ?&lt;br /&gt;
&lt;br /&gt;
What implementation of Pascal are you using?  What kind of computer and operating system?&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392265/re-moving-from-byteint-array-to-record/#392265</guid>
      <pubDate>Fri, 12 Jun 2009 20:49:10 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392287/re-moving-from-byteint-array-to-record/#392287</link>
      <description>I appreciate your reply...&lt;br /&gt;
&lt;br /&gt;
However, I am not really looking for help in deciphering how to cast the byte(ints) into the &lt;em&gt;individual&lt;/em&gt; fields but was really wondering whether there was some Pascal capability to overlay (or point to) the same data but from the viewpoint of differently defined stuctures and have them correctly "cast" automatically.   I may be asking for a ability that does not exist.  But simplistically I am looking for:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
custfile:=bulkfile.bulk[1..28];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As to your final question...in my example what is held in bytes 29-1000 is superfluous to the problem but can be understood if one rationalizes that bulkfile can hold the data in the same way for various other file structures.  Thus I could have an address record that is 130 bytes long and when stored in the bulk file it would take up the first 130 bytes of bulkfile.bulk.  Note one of the fields of the bulkfile record is "reclen" which would of course hold a 28 in my original example thus allowing the programmer to know how many significant bytes the bulkfile.bulk field held.&lt;br /&gt;
&lt;br /&gt;
Thanks again...&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392287/re-moving-from-byteint-array-to-record/#392287</guid>
      <pubDate>Sat, 13 Jun 2009 07:00:10 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392294/re-moving-from-byteint-array-to-record/#392294</link>
      <description>: I &lt;br /&gt;
: may be asking for a ability that does not exist.  But simplistically &lt;br /&gt;
: I am looking for:&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: custfile:=bulkfile.bulk[1..28];&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
I'm fairly certain that such a thing does not exist in classical Pascals such as described by Jensen and Wirth.&lt;br /&gt;
&lt;br /&gt;
I think you might be able to do something like this in Turbo Pascal or FreePascal.  I'd have to give it some thought as to exactly how.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392294/re-moving-from-byteint-array-to-record/#392294</guid>
      <pubDate>Sat, 13 Jun 2009 08:42:59 -0700</pubDate>
      <category>Pascal</category>
    </item>
    <item>
      <title>Re: Moving from byteint array to record</title>
      <link>http://www.programmersheaven.com/mb/pasprog/392258/392299/re-moving-from-byteint-array-to-record/#392299</link>
      <description>How about Move();&lt;br /&gt;
&lt;br /&gt;
Just copy all the data from the ByteArray to the start address of the custfile. This should fill in all the data.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
 Move(bulkfile.bulk, custfile, 28);
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/pasprog/392258/392299/re-moving-from-byteint-array-to-record/#392299</guid>
      <pubDate>Sat, 13 Jun 2009 12:46:03 -0700</pubDate>
      <category>Pascal</category>
    </item>
  </channel>
</rss>