[fpc-pascal] Case in Record
Frank Peelo
f26p at eircom.net
Thu Oct 8 15:11:59 CEST 2009
On 07/10/2009 16:39, Jürgen Hestermann wrote:
>>> IIRC, there is a difference. With the second declaration the compiler
>>> can add a run-time check that the correct memebrs are accessed based
>>> on the value of X.
>>> Unfortunately, I cannot find the compiler switch.
>>
>> FPC has no support for this.
>
>
> And I don't know any other Pascal Compiler who does any checks in this
> direction. Do some?
Given that the OP was asking about learning, maybe it would be worth
mentioning that the way we normally have "data structures which hold
different data" these days is by polymorphism in objects or classes.
Instead of having an array of variant records, each of which might hold
a description of a circle, square or pentagon depending on the value of
a tag variable, we would now have an array of Shape, where Shape is a
class instance or pointer to an object. The actual elements of the array
would be Circle, Square or Pentagon, where these are types descended
from Shape.
This has several benefits, not least the fact that new shapes can be
added more easily than in the variant record case.
The stuff that has been said about variant records is all good, and
variant records still have uses in some cases, but we don't want to
mislead the OP into thinking that this is necessarily the way to go with
new programs.
FP
More information about the fpc-pascal
mailing list