defaria@hpcupt3.cup.hp.com (Andy DeFaria) (05/17/91)
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;