TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: BOB DUNNELL
from: LAWRENCE GORDON
date: 1996-06-27 09:48:00
subject: Reading Pascal Files

On 06-25-96, BOB DUNNELL wrote to LAWRENCE GORDON:
BD> LG> Anyone know how to read a Pascal data file and convert the file
BD> LG> structure to  PB?  The first data byte of a string is usually the
BD>Depends on how the string is stored.  Some people store as arrays of
BD>char variables to be more compatible with C, some do it with the
BD>packed array of char (aka STRING in Pascal) which does contain the
BD>length, etc.  Most people would probably use the packed array of char
BD>since that's Pascal's default string.  I tend to use a regular
BD>array of characters, null-terminated at the end if it ends before the
BD>array ends, as it seems more portable.
The question is where the offset for the string length is in the data
file. Normally it is the first byte, so would you have to have a routine
that returned the value of the offset so you could determine the length
of the string? If you DIM a string in PB, such as DIM MYVAR AS
STRING * 50, the PB data file will reserve 50 bytes for MYVAR, and
MYVAR will contain nothing but nulls until the data is initialized or
a value is assigned to MYVAR, at which time the nulls are replaced by
CHR$(32)s.  In PB, finding the offset for each data element is simple;
the Pascal method, by contrast, is rather clunky. The question remains,
however, how you convert it.
For instance, let's suppose you have a Pascal data file with this
structure:
type
 employee = record
 name : string[30];
 address : string[30];
 salary : real;
 married : boolean;
 num_children : byte;
end;
Your mission, should you choose to accept it, is to help me convert
this data structure to a PB record-type and give me a clue to reading
the file, with particular attention given the string-length offsets. :)
BD> LG> An example would be appreciated.
BD>however, I do NOT have one of those.
I have just given one to you. Consider this to be your lucky day. :)
--- WILDMAIL!/WC v4.12 
---------------
* Origin: Toast House Remote (1:100/560.1)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.