[fpc-pascal] Case in Record

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Oct 6 16:00:09 CEST 2009


On Tue, Oct 6, 2009 at 10:13 AM, 章宏九 <secludedsage at gmail.com> wrote:
> Type
>  MyRec = Record
>          X : Longint;
>          Case byte of
>            2 : (Y : Longint;
>                 case byte of
>                 3 : (Z : Longint);
>                 );
>          end;

I think the cases are useless here. AFAIK the case inside record is
utilized to give multiple options of use for the same memory area. It
is used so that the same structure can have multiple uses without
wasting space. But this is pointless if the case has only 1 option, it
should have 2 or more to make sense. For me the above is the same as:

Type
  MyRec = Record
     X : Longint;
     Y: Longint;
     Z: Longint;
  end;

I think that visibility isn't in place because even with multiple
options you can access any of them at any given time even if they
conflict.

> And the wiki said that Object is not used very
> much. Does this mean that Object is deprecated?

Deprecated means that the feature will or may be removed in the
future, but AFAIK there are no plans to remove support for Object. So
I would say it's a legacy feature (from Turbo Pascal), but not
deprecated at the moment.

If you are not sure which one to use, then just use classes.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list