: bulkrec = record
: job : LongInt;
: relation : packed array [1..8] of char;
: reclen : LongInt;
: bulk : array [1.. 1000] of ByteInt;
:
: pbulkrec = ^bulkrec;
:
:
: and then I have another record like:
:
: custfile = record
: custnum : ShortNat;
: group : ShortNat;
: name : packed array [1..20] of char;
: flag1 : boolean;
: flag2 : boolean;
: flag3 : boolean;
: flag4 : boolean;
: end;
:
: pcustfile = ^custfile;
:
:
: Problem then is that the bulkrec.bulk field actually
: holds the custfile data and I want to move it from that
: array into custfile record... i.e.
:
: custnum is a 2 byte field so the concatenation of
: bulk[1] and bulk[2] holds its value.
:
: group also is a 2 byte field so the concatenation of
: bulk[3] and bulk[4] holds its value.
:
: name is 20 byte field and thus
: bulk[5] thru bulk[24] hold its value.
:
: flags1-4 hold 1 byte a piece
: bulk[25] to bulk[28] respectively.
:
: How do I make this assignment from the bulkrec.bulk
: variable to the custfile record???
:
: Any help appreciated.
:
:
The first problem I see is your declarations
pbulkrec : ^bulkrec;
pcustfile : ^custfile;
where you declare
pbulkrec and
pcustfile 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:
pbulkrec : bulkrec;
pcustfile : custfile;
If you really need these to be pointers I'll leave it to you to make that adjustment.
: custnum is a 2 byte field so the concatenation of
: bulk[1] and bulk[2] holds its value.
I'm assuming that the definition of
BulkRec 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
with pbulkrec do
with pcustfile do
CustNum := 128*Bulk[1] + Bulk[2] ;
This assumes that
Bulk[1] is the most significant byte, but it could be that
Bulk[2] is the MSB.
However,
Bulk is signed and
CustNum is unsigned. I think this is more likely:
with pbulkrec do
with pcustfile do
CustNum := (256*(Bulk[1] + 128) MOD 32768) + (Bulk[2] + 128 ;
Adding 128 to each
Bulk element shifts it into positive territory, and the MOD operator keeps
CustNum in range. Of course this assumes that the original programmer took this same approach.
: name is 20 byte field and thus
: bulk[5] thru bulk[24] hold its value.
for i := 1 to 20 do
name[i] := bulk[i + 4] ; { there may be problems with pack and unpack }
: flags1-4 hold 1 byte a piece
: bulk[25] to bulk[28] respectively.
flag1 := (bulk[25] = 0) ; { assume zero means FALSE }
flag2 := (bulk[26] = 0) ; { any else means TRUE }
flag3 := (bulk[27] = 0) ;
flag4 := (bulk[28] = 0) ;
What do
Bulk[29] .. Bulk[1000] hold ?
What implementation of Pascal are you using? What kind of computer and operating system?