Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpl-opus!hpcc05!hpyhde4!hpycla!hpcuhc!hpcupt3!defaria@hpcupt3.cup.hp.com From: defaria@hpcupt3.cup.hp.com (Andy DeFaria) Newsgroups: comp.lang.pascal Subject: Reading other programs variable length records? Message-ID: <45670016@hpcupt3.cup.hp.com> Date: 16 May 91 17:33:53 GMT Organization: Hewlett Packard, Cupertino Lines: 60 I'm trying to read a file, output by another program, with TP that has a certain, predefined format and I'm having some difficulties. I have a few questions about this. First, the format of the file is roughly as: RecordType : Integer RecordLength : Integer Data : { varies } Questions: 1) RecordType should really be an enumeration but the values of the enumeration are fixed and non-sequential. Is there a way that I can tell TP what I want the enumeration values to be? In Ada I can do this. 2) Trying to use a variant record in TP doesn't work because 1) it would require the record to be defined as: RecordLength : Integer RecordType : Integer Data : { varies } or I could put RecordLength in each Data field. Still attempting to do: Var FromFile : File of ThisCrazyRecordType; ARecordVar : ThisCrazyRecordType Read (FromFile, ARecordVar); would cause the largest record variant to be read in and this is not what I want since the size of the records is not constant but varies with the record type. So the question is: How do you define this type of a record? I can see a way to do this but it doesn't seem ideal and I'm wondering if there is a better way. Basically my work around consists of writing a procedure to read every type of record and assembling a Pascal variant record of all record types layed out any way I want: Procedure ReadTheFunnyRecord (Var FromFile : File; Var ReturnData : ThisCrazyRecordType); Var Header : HeaderType; Data : DataType; Begin BlockRead (FromFile, Header, SizeOf (Header)); BlockRead (FromFile, Data, Header.Length)); Case Header.RecordType of { Large case statement to change RecordType to an ascending } { enumeration value in ReturnData and format the Data portion of } { ReturnData } end; end;