Page 1 of 1

Reaction getscreenmode.gadget issue

Posted: Sat Jun 04, 2016 8:39 pm
by xenic
While I was helping LyleHaze look for a getscreenmode example at http://www.os4coding.net, I posted an example that used this:

Code: Select all

LAYOUT_AddChild, objects[OID_SCREENMODE] = IIntuition->NewObject(NULL, "getscreenmode.gadget",
GA_ID, OID_SCREENMODE,
GA_RelVerify, TRUE,
GA_Disabled,FALSE,
GETSCREENMODE_DisplayID,0,
GETSCREENMODE_MinDepth, 0,
GETSCREENMODE_MaxDepth, 32,
TAG_END),
Both Lyle and I discovered that the program only worked when certain other programs were running.

The example program always works when I cnanged the above code to this:

Code: Select all

#define GetScreenModeClass IGetScreenMode->GETSCREENMODE_GetClass()

LAYOUT_AddChild, objects[OID_SCREENMODE] = IIntuition->NewObject(GetScreenModeClass, NULL,
GA_ID, OID_SCREENMODE,
GA_RelVerify, TRUE,
GA_Disabled,FALSE,
GETSCREENMODE_DisplayID,0,
GETSCREENMODE_MinDepth, 0,
GETSCREENMODE_MaxDepth, 32,
TAG_END),
The getscreenmode_gc.doc states this:

GETSCREENMODE_GetClass
This function is deprecated as of V52.
Use the "getscreenmode.gadget" public class ID instead.

Can anyone explain why "getscreenmode.gadget" doesn't work reliably but the deprecated function does??

Re: Reaction getscreenmode.gadget issue

Posted: Sat Jun 04, 2016 9:04 pm
by salass00
Have you opened the class library first by calling either IExec->OpenLibrary() or IIntuition->OpenClass()? If not that's why it doesn't work...

It is recommended to use IIntuition->OpenClass() and pass the class pointer obtained from there to IIntuition->NewObject() rather than using the public class name as not only does it make it harder to make a mistake like forgetting to open the class before using it, it has also has less overhead since NewObject() doesn't need to search the public classes list for the class in question.

Re: Reaction getscreenmode.gadget issue

Posted: Sat Jun 04, 2016 9:45 pm
by xenic
salass00 wrote:Have you opened the class library first by calling either IExec->OpenLibrary() or IIntuition->OpenClass()? If not that's why it doesn't work...

It is recommended to use IIntuition->OpenClass() and pass the class pointer obtained from there to IIntuition->NewObject() rather than using the public class name as not only does it make it harder to make a mistake like forgetting to open the class before using it, it has also has less overhead since NewObject() doesn't need to search the public classes list for the class in question.
Thanks for the info. I was using -lauto which might explain why some classes worked but getscreenmode.gadget did not. I don't write GUI programs much and my first inclination is to check the SDK Reaction examples and autodocs but that's not as helpful as it should be.