home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / pascal / 4901 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  1.5 KB

  1. Path: sparky!uunet!cs.utexas.edu!torn!utzoo!dciem!r-node!bville!greg.vigneault
  2. From: greg.vigneault@bville.gts.org (Greg Vigneault)
  3. Newsgroups: comp.lang.pascal
  4. Subject: ARRAY INDEX??
  5. Message-ID: <529.495.uupcb@bville.gts.org>
  6. Date: 18 Aug 92 13:27:00 GMT
  7. Reply-To: greg.vigneault@bville.gts.org (Greg Vigneault)
  8. Organization: Baudeville BBS - Toronto, Canada 416-283-0114/6059* *v32bis/HST
  9. Lines: 34
  10.  
  11. GD> Is there anyway to declare and array of records so that you can
  12.   > index the array by a string?
  13.  
  14.  Yes, if you're using Turbo Pascal.
  15.  
  16.  Here's an example using a single record, but the technique
  17.  should also work with an array of records ...
  18.  
  19. (********************************************************************)
  20.  PROGRAM foo;
  21.  (* we'll make the array look like a string ...                     *)
  22.  TYPE   CharArray   = RECORD
  23.                         Length  : BYTE;
  24.                         Data    : ARRAY [1..255] OF CHAR;
  25.                       END;
  26.  
  27.  VAR    AnyRec  : CharArray;                (* create the space     *)
  28.         RecStr  : String ABSOLUTE AnyRec;   (* string on array      *)
  29.         loopc   : BYTE;
  30.  BEGIN
  31.         RecStr := 'Hello, world!';          (* assign string&array  *)
  32.  
  33.         FOR loopc := 1 TO AnyRec.Length     (* prove it             *)
  34.             DO Write( AnyRec.Data[loopc] );
  35.  
  36.  END.
  37. (********************************************************************)
  38.  
  39.  Greg_
  40.  
  41.  Aug.18.1992.Toronto.Canada.
  42.  greg.vigneault@bville.gts.org
  43.  gregsv@eastern.com
  44.                                                                    
  45.