Article View: comp.lang.pascal.borland
Article #185Re: CASE in records
From: byatesiii
Date: Tue, 30 May 2000 00:00
Date: Tue, 30 May 2000 00:00
53 lines
2510 bytes
2510 bytes
In article <3933FF8D.FFBE7575@vgrieken.demon.nl>,
Xy <xy@vgrieken.demon.nl> wrote:
> Hey all
>
> Could someone please explain me these piece of code:
>
> tPolygonRec = Record
> ...
> ...
> Case Integer of { Cases for the various polygon types }
> 1 : (AB1, AB2, AB3 : UVCoord; Intensity : Byte);
> 2 : (AB4, AB5, AB6 : UVCoord; I1, I2, I3 : Byte);
> 3 : (AB7, AB8, AB9 : UVCoord);
> 4 : (UV1, UV2, UV3 : UVCoord);
> 5 : (AC1, AC2, AC3 : UVCoord; I_tensity : Byte);
> 6 : (AC4, AC5, AC6 : UVCoord; I4, I5, I6 : Byte);
> 7 : (AC7, AC8, AC9 : UVCoord; PT1, PT2, PT3 : UVCoord);
> End;
>
> -or-
>
> Type Register = Record
> Case Byte of
> 0 : (w1, w2 : Word);
> 1 : (b1, b2, b3, b4 : Byte);
> End;
>
> (I copied these pieces of code from somebody elses sources)
>
> What i don't understand is the 'CASE' statements in these records. Can
> someone please explain to me how i use 'CASE' in records and why this
is
> useful?? Thnx in advance!
>
> Grtnx
> Xy
>
>
There are bound to be better replies, as I'm not an expert.
These are also referred to as "Variant records".
It allows you to store different data-types or data-sizes within the
same record.
Your 2nd example allows a person to store either two words or four
bytes (same size) within the record, and Pascal chooses which one by
the type of the data you are storing there (byte or word).
In some implementations I think the size of each variant had to be the
same, or the larger ones came first. Your first example doesn't appear
to follow this restriction. But then again, I'm a UCSD Pascal
programmer... the only one left, I imagine :)
Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID:
<8h10un$lln$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3933FF8D.FFBE7575@vgrieken.demon.nl>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 108ebd,60a819bd5bee7e02 X-Google-Attributes: gid108ebd,public X-Google-Thread: 111659,60a819bd5bee7e02 X-Google-Attributes: gid111659,public From: byatesiii@my-deja.com Subject: Re: CASE in records Date: 2000/05/30 Message-ID: <8h10un$lln$1@nnrp1.deja.com> X-Deja-AN: 629102839 References: <3933FF8D.FFBE7575@vgrieken.demon.nl> X-Http-Proxy: 1.1 x57.deja.com:80 (Squid/1.1.22) for client 4.17.20.4 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Tue May 30 18:23:41 2000 GMT X-MyDeja-Info: XMYDJUIDbyatesiii Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows 95)