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

{
 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
 LG> 
 LG> The question is where the offset for the string length is in the data
 LG> file. Normally it is the first byte, so would you have to have a
 
 LG> Your mission, should you choose to accept it, is to help me convert
 LG> this data structure to a PB record-type and give me a clue to reading
 LG> the file, with particular attention given the string-length offsets.
 
Using the example (of Pascal code, so others can compile it, those
averse to Pascal should stop reading NOW), I created a file.  That example
is found at the end of this message -- just comment out the origin junk
and it'll compile in Turbo Pascal.  Anyway, when I did that, the
system displayed a filesize of 70 bytes, and a record of 70 bytes.
 
Each string of 30 is in reality a 31-byte structure.  There are 30
bytes for characters, PRECEDED by a 1 byte length delimiter which
tells the length of the string stored within the 30 bytes.  Then
the real is 6 bytes, and the other two are 1 byte each, which
adds up to 70 bytes.
 
Now, as for a string that is NOT qualified with a [n] on the end,
I don't know...those are often packed and might screw the record
size up somewhat.}
 
type
    employee = record
             name,                      {31 bytes}
             address : string[30];      {31 bytes}
             salary        : real;      {6  bytes}
             married       : boolean;   {1  byte}
             num_children  : byte;      {1  byte}
    end;                                {70 bytes}
 
var
   temp  : employee;                     {temp record}
   tempf : file of employee;             {temp file handle}
 
begin
     with temp do                       {assign values to record}
     begin
          name := 'Lawrence Gordon';
          address := 'Ladue, home of the rich.';
          salary := 780000.45;
          married := true;
          num_children := 1;
     end;
     writeln(sizeof(temp));             {display size of record}
 
     assign(tempf,'employee.dat');      {write to disk}
     rewrite(tempf);
     write(tempf,temp);
     close(tempf);
end.
 
 
 
 
 
... rtfm (314) 843-1855
***
 þ Blue Wave/QWK v2.12 þ
--- GEcho/32 1.20/Pro
---------------
* Origin: rtfm 314.843.1855 (1:100/340)

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™.