Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!uakari.primate.wisc.edu!caen!kuhub.cc.ukans.edu!maverick.ksu.ksu.edu!wyoung From: wyoung@cis.ksu.edu (William J. Young) Newsgroups: comp.lang.pascal Subject: Re: need a little flexibility Message-ID: <1991Apr26.145543.4741@maverick.ksu.ksu.edu> Date: 26 Apr 91 14:55:43 GMT References: <1991Apr24.183315.7997@ux1.cso.uiuc.edu> <1991Apr24.235739.25115@watmath.waterloo.edu> <91115.111155IO92203@MAINE.BITNET> Sender: news@maverick.ksu.ksu.edu (The News Guru) Organization: Kansas State University, Department of Computing and Information Sciences Lines: 42 Nntp-Posting-Host: procyon.cis.ksu.edu In article <91115.111155IO92203@MAINE.BITNET> IO92203@MAINE.BITNET (Scott Maxell) writes: >In article <1991Apr24.235739.25115@watmath.waterloo.edu>, >nmouawad@watmath.waterloo.edu (Naji Mouawad) says: >> >>Block = record >> x : byte; >> y : byte; >> case boolean of >> True : (data : array[1..252] of byte); >> False: (dataw: array[1..126] of word); >>end; >> > > This last approach won't work as stated because a variant record can >only contain one of the possible fields declared. Have you tried it? It does work. A variable of a variant record type does allow accessing either of the named fields. It's up to the programmer to do the error checking necessary to avoid misuse. > The field in the variant >should also have a declared variable and not just a type. ^^^^^^ > >Type > Block = RECORD > X, > Y : Byte; > Case WordData : Boolean OF > True : ( DataW : ARRAY [1..126] OF Word ); > False : ( Data : ARRAY [1..252] OF Byte ); > END; (* record *) > ** rest deleted ** Not necessary. This is nice for doing the error checking I mentioned, but you can leave it off and access either field as needed. -- ---------------------------- Bill Young wyoung@cis.ksu.edu