Dot syntax for types?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Dot syntax for types?

Ryan Joseph
I remember I heard about a mode switch that requires "type groups” (what are these called btw?) to use a . and be prefixed. For example:

type
        TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);


TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is declared so I want the type to be explicitly TGLType.GL_FLOAT in all cases). I need to make some wrappers around OpenGL types and I thought this would be a nice way to do it instead of declaring a bunch of constants with prefixes but I just can’t remember how to handle that dot syntax (maybe it’s in the trunk under development). Thanks.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Free Pascal - General mailing list
Am 14.01.2018 03:42 schrieb "Ryan Joseph" <[hidden email]>:
I remember I heard about a mode switch that requires "type groups” (what are these called btw?) to use a . and be prefixed. For example:

type
        TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);


TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is declared so I want the type to be explicitly TGLType.GL_FLOAT in all cases). I need to make some wrappers around OpenGL types and I thought this would be a nice way to do it instead of declaring a bunch of constants with prefixes but I just can’t remember how to handle that dot syntax (maybe it’s in the trunk under development). Thanks.

Those types are called enumerations or enums for short, the variant that requires a point are called scoped enums and the compiler directive you're looking for is "{$scopedenums on}" and only needs to be used for declaring the enum, not when using it. As the switch is a local one you can even mix scoped and unscoped enum declarations in the same unit. The switch is available at least since 3.0.0 though it isn't mentioned in the language reference guide about enums ( https://freepascal.org/docs-html/current/ref/refsu4.html#x26-280003.1.1). 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Ryan Joseph


> On Jan 14, 2018, at 3:27 PM, Sven Barth via fpc-pascal <[hidden email]> wrote:
>
> Those types are called enumerations or enums for short, the variant that requires a point are called scoped enums and the compiler directive you're looking for is "{$scopedenums on}" and only needs to be used for declaring the enum, not when using it. As the switch is a local one you can even mix scoped and unscoped enum declarations in the same unit. The switch is available at least since 3.0.0 though it isn't mentioned in the language reference guide about enums ( https://freepascal.org/docs-html/current/ref/refsu4.html#x26-280003.1.1).
>

Ah yes enums. {$scopedenums on} was what I was looking for but it looks like even if I remembered what they were called I still wouldn’t have found the switch. Thanks again.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Michael Van Canneyt
In reply to this post by Ryan Joseph


On Sun, 14 Jan 2018, Ryan Joseph wrote:

> I remember I heard about a mode switch that requires "type groups” (what are these called btw?) to use a . and be prefixed. For example:
>
> type
> TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);
>
>
> TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is declared so I want the type to be explicitly TGLType.GL_FLOAT in all cases). I need to make some wrappers around OpenGL types and I thought this would be a nice way to do it instead of declaring a bunch of constants with prefixes but I just can’t remember how to handle that dot syntax (maybe it’s in the trunk under development). Thanks.

Try
{$SCOPEDENUMS ON}

see
https://www.freepascal.org/docs-html/current/prog/progsu70.html#x77-760001.2.70

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Free Pascal - General mailing list
On 14.01.2018 09:56, Michael Van Canneyt wrote:

>
>
> On Sun, 14 Jan 2018, Ryan Joseph wrote:
>
>> I remember I heard about a mode switch that requires "type groups”
>> (what are these called btw?) to use a . and be prefixed. For example:
>>
>> type
>>     TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);
>>
>>
>> TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is
>> declared so I want the type to be explicitly TGLType.GL_FLOAT in all
>> cases). I need to make some wrappers around OpenGL types and I thought
>> this would be a nice way to do it instead of declaring a bunch of
>> constants with prefixes but I just can’t remember how to handle that
>> dot syntax (maybe it’s in the trunk under development). Thanks.
>
> Try
> {$SCOPEDENUMS ON}
>
> see
> https://www.freepascal.org/docs-html/current/prog/progsu70.html#x77-760001.2.70

Maybe a bit of that documentation can be added to the enumerations
section of the language reference guide as well? After all the
functionality itself is part of the language and one might not know that
that this feature a) exists and b) that it needs a directive to be enabled.

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Michael Van Canneyt


On Sun, 14 Jan 2018, Sven Barth via fpc-pascal wrote:

> On 14.01.2018 09:56, Michael Van Canneyt wrote:
>>
>>
>> On Sun, 14 Jan 2018, Ryan Joseph wrote:
>>
>>> I remember I heard about a mode switch that requires "type groups”
>>> (what are these called btw?) to use a . and be prefixed. For example:
>>>
>>> type
>>>     TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);
>>>
>>>
>>> TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is
>>> declared so I want the type to be explicitly TGLType.GL_FLOAT in all
>>> cases). I need to make some wrappers around OpenGL types and I thought
>>> this would be a nice way to do it instead of declaring a bunch of
>>> constants with prefixes but I just can’t remember how to handle that
>>> dot syntax (maybe it’s in the trunk under development). Thanks.
>>
>> Try
>> {$SCOPEDENUMS ON}
>>
>> see
>> https://www.freepascal.org/docs-html/current/prog/progsu70.html#x77-760001.2.70
>
> Maybe a bit of that documentation can be added to the enumerations
> section of the language reference guide as well? After all the
> functionality itself is part of the language and one might not know that
> that this feature a) exists and b) that it needs a directive to be enabled.
Absolutely right, and I had already added this to my todo list :)

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Dot syntax for types?

Free Pascal - General mailing list
On 14.01.2018 16:19, Michael Van Canneyt wrote:

>
>
> On Sun, 14 Jan 2018, Sven Barth via fpc-pascal wrote:
>
>> On 14.01.2018 09:56, Michael Van Canneyt wrote:
>>>
>>>
>>> On Sun, 14 Jan 2018, Ryan Joseph wrote:
>>>
>>>> I remember I heard about a mode switch that requires "type groups”
>>>> (what are these called btw?) to use a . and be prefixed. For example:
>>>>
>>>> type
>>>>     TGLType = (GL_FLOAT, GL_UNSIGNED_BYTE);
>>>>
>>>>
>>>> TGLType.GL_FLOAT would be the full name (note GL_FLOAT already is
>>>> declared so I want the type to be explicitly TGLType.GL_FLOAT in all
>>>> cases). I need to make some wrappers around OpenGL types and I thought
>>>> this would be a nice way to do it instead of declaring a bunch of
>>>> constants with prefixes but I just can’t remember how to handle that
>>>> dot syntax (maybe it’s in the trunk under development). Thanks.
>>>
>>> Try
>>> {$SCOPEDENUMS ON}
>>>
>>> see
>>> https://www.freepascal.org/docs-html/current/prog/progsu70.html#x77-760001.2.70
>>>
>>
>> Maybe a bit of that documentation can be added to the enumerations
>> section of the language reference guide as well? After all the
>> functionality itself is part of the language and one might not know that
>> that this feature a) exists and b) that it needs a directive to be
>> enabled.
>
> Absolutely right, and I had already added this to my todo list :)

Perfect :)

Regards,
Sven

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal