[comp.lang.pascal] Turbo READ/WRITE

milne@ics.uci.edu (Alastair Milne) (07/12/89)

>>One of the advantages of Borland's nonstandard Read/Write vs. Get/Put
>>is the ability to read or write any enumerated type. This is most
>>useful when one or more variables in a record are enumerated types

    You can do no more or less with the overloaded Read and Write than you
    can with standard Get or Put.  To use them for I/O of enumeration means
    you are maintaining a file of the enumeration type -- conceivable, but I
    don't think it's often done.  

      type stones = ( granite, gneiss, shale, bedrock, basalt);
      var  list: file of stones;

      ...
      get( list);    { standard Pascal (and many others) }
      newstone := list^;

      or

      Read( list, NewStone);   { Borland }

    whereas what most people want is the name of each constant available for
    I/O, as in;

      writeln('You must now dig ',x,' metres through ', CrntStone,'.');

      giving at execution:

      You must now dig 12 metres through granite.

    To this the overloaded Read and Write have no application.

>>. As I remember "standard" Pascal in my distant past, one had to convert
>>an enumerated  type  to an ordinal type (often a byte or integer) and
>>then get/put that. 

    Not at all.  Just declare the file's base type to be that enumeration, as
    above.  Assuming what you really want is a file consisting of an
    enumeration.

>>That limitation is a real bother when using records.

    Don't forget that with Turbo's Read/Write, you are still using records.

      type  entry = record
		      name: string;
		      address: addressrec;
		      phone: digits;
		      gender: (female, male);
		      end;
      var  listing: file of entry;
	   EachEntry: entry;

      .... 
      read( Listing, EachEntry);

    Alastair Milne