[fpc-pascal] How do record variants without a field name?

leledumbo leledumbo_cool at yahoo.co.id
Sat Apr 9 14:25:17 CEST 2016

> I posted this to Stack Overflow
but it hasn't gotten any feedback

There are 2 answers already ATM, so I won't add the 3rd one (hard to get
upvote :p)

> what's the purpose of the Case Boolean part?

That's what makes variant record different from ordinary record.

> I understand that you can do case MyVal: Boolean; then MyVal becomes the
> field selector. However, what is the purpose when there is no field
> selector, just a type?

The same, it's useful when you have no need to check which variant is active
ATM. I seldom do this, I always think the selector can be useful someday.

> I don't quite understand what the selector-type is

It's in the first sentence: "With each variant-part shall be associated a
type designated the selector-type possessed by the variant-part."
Just imagine there is this selector-type owned by variant-part, whose
meaning is decided later because it depends on conditions explained

> why it would be a new ordinal-type

because multiple constant values in the case-constant-list does not have a
type yet, so it's a new ordinal type when used.

> Wouldn't the selector-type just be the type like in case Boolean of?

yes and no, see above.

> And what does each case-constant-list having only one case-constant have
> to do with it?

When only one case-constant is used, there's no confusion, each of the
constant will of course should be in the range of tag-type. Hence, no new
type required to be constructed.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/How-do-record-variants-without-a-field-name-tp5724866p5724868.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.

More information about the fpc-pascal mailing list