Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!strath-cs!ex-dcs!exua!CDHWilli From: CDHWilli@exua.exeter.ac.uk (Charles Williams) Newsgroups: comp.lang.pascal Subject: Re: need a little flexibility Message-ID: Date: 27 Apr 91 23:04:22 GMT References: <1991Apr24.183315.7997@ux1.cso.uiuc.edu> <1991Apr24.235739.25115@watmath.waterloo.edu> <91115.111155IO92203@MAINE.BITNET> Sender: CDHWilli@exua.exeter.ac.uk Organization: Computer Unit. - University of Exeter. UK Lines: 77 In-reply-to: IO92203@MAINE.BITNET's message of 25 Apr 91 15:11:55 GMT [Sensible text and helpful reply deleted] Scott Maxell joins in... SM> SM> This last approach won't work as stated because a variant record can SM>only contain one of the possible fields declared. The field in the variant SM>should also have a declared variable and not just a type. SM> SM>Type SM> Block = RECORD SM> X, SM> Y : Byte; SM> Case WordData : Boolean OF SM> True : ( DataW : ARRAY [1..126] OF Word ); SM> False : ( Data : ARRAY [1..252] OF Byte ); SM> END; (* record *) SM> SM>VAR SM> WordData : BOOLEAN; SM> OneWord : Word; SM> OneByte : Byte; SM> SM>BEGIN SM> B.WordData := True; (* or false depending on what your data is. *) SM> OneByte := ????; (* Your byte data. *) SM> OneWord := ????; (* Your word data. *) SM> n := ????; (* Array index. *) SM> Case B.WordData OF SM> True : B.Data [n] := OneByte; SM> False : B.DataW [n] := OneWord; SM> END; (* case *) SM>END; SM> SM> When adding data to a variant record, there needs to be a value placed in SM>the tag field, or you will generally get an error. The label associated with a variant field is optional. For example here is a routine to "and" two integers. It is *real* code, from a *real* program, it *really* works on a Sparcstation and according to my compiler is ISO and ANSI compliant. Of course whether it works on a particular machine depends on the word length. {------------------------------------------------------------------------------ / ANDint(I,J) logically ANDs integers I,J /-----------------------------------------------------------------------------} function ANDint( I,J: integer ): integer; const IntDigits = 32; type Overlay = record case boolean of False: ( IntType: integer); True : ( SetType: set of 1..IntDigits ) end{record}; var { Dual type variables } A, B: Overlay; begin{ANDint} A.IntType:=I; B.IntType:=J; A.SetType:=A.SetType*B.SetType; ANDint:=A.IntType end{ANDint}; SM>"What I need is a computer that will do what I want it to SM> do, not what I tell it to do..." I can see why ;-) =============================================================================== ============ My signature and I have separated for a trial period ============= ===============================================================================