home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!torn!utzoo!dciem!r-node!bville!greg.vigneault
- From: greg.vigneault@bville.gts.org (Greg Vigneault)
- Newsgroups: comp.lang.pascal
- Subject: ARRAY INDEX??
- Message-ID: <529.495.uupcb@bville.gts.org>
- Date: 18 Aug 92 13:27:00 GMT
- Reply-To: greg.vigneault@bville.gts.org (Greg Vigneault)
- Organization: Baudeville BBS - Toronto, Canada 416-283-0114/6059* *v32bis/HST
- Lines: 34
-
- GD> Is there anyway to declare and array of records so that you can
- > index the array by a string?
-
- Yes, if you're using Turbo Pascal.
-
- Here's an example using a single record, but the technique
- should also work with an array of records ...
-
- (********************************************************************)
- PROGRAM foo;
- (* we'll make the array look like a string ... *)
- TYPE CharArray = RECORD
- Length : BYTE;
- Data : ARRAY [1..255] OF CHAR;
- END;
-
- VAR AnyRec : CharArray; (* create the space *)
- RecStr : String ABSOLUTE AnyRec; (* string on array *)
- loopc : BYTE;
- BEGIN
- RecStr := 'Hello, world!'; (* assign string&array *)
-
- FOR loopc := 1 TO AnyRec.Length (* prove it *)
- DO Write( AnyRec.Data[loopc] );
-
- END.
- (********************************************************************)
-
- Greg_
-
- Aug.18.1992.Toronto.Canada.
- greg.vigneault@bville.gts.org
- gregsv@eastern.com
-
-