Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2023-06

SDL2 Event Registration (and case statements)

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rafael Picanço

Hi,

The SDL2 documentation recommends you to register constants with:

Uint32 SDL_RegisterEvents(int numevents);
numevents = the number of events to be allocated.
Returns the beginning event number, or (Uint32)-1 if there are not enough user-defined events left.
https://wiki.libsdl.org/SDL2/SDL_RegisterEvents

The SDL_RegisterEvents result is not known at compile time, so one can't use them as case conditions. So, Is there a workaround for building these constants at compile time?

Best,
R

Reply by email

Guillermo Martínez Jiménez
to Rafael Picanço

Hi.

Show quoted text 10 lines
The SDL2 documentation recommends you to register constants with: Uint32 SDL_RegisterEvents(int numevents); numevents = the number of events to be allocated. Returns the beginning event number, or (Uint32)-1 if there are not enough user-defined events left. The SDL_RegisterEvents result is not known at compile time, so one can't use them as case conditions. So, Is there a workaround for building these constants at compile time?

If you know how many events were registered, then you can create constants. Else, you can't.

Best, R

Guillermo "Ñuño" Martínez

Reply by email

Rafael Picanço

Thanks Guilhermo,

Just to clarify, I do have a limited number of events. Lets say, 2 events. So, using the SDL_RegisterEvents function, is it possible to define these two new events as normal constants so they will be known at compile time and will make Free Pascal case statements happy?

Best,
R

Reply by email

Guillermo Martínez Jiménez
to Rafael Picanço

El Sun, 25 Jun 2023 13:42:00 -0300
Rafael Picanço via fpc-pascal

Thanks Guilhermo,

You welcome. :)

Show quoted text 5 lines
Just to clarify, I do have a limited number of events. Lets say, 2 events. So, using the SDL_RegisterEvents function, is it possible to define these two new events as normal constants so they will be known at compile time and will make Free Pascal case statements happy?

Yes, you can. But be careful that no other events are registered before yours.

Best, R

Regards,
Guillermo Martínez

Reply by email