Older OS (pre 3.something) FrmGetObjectIndex() would fatal if the object was
not found!

Check the OS version and if it's an early one that crashes instead of
returning an error, patch the FrmGetObjectIndex() trap a local function.

Example:


// generalized structure that matches the pre OS4 structures
typedef struct
        {
        //WindowType                            window; // the old
WindowType struct was 40 bytes long
        UInt8                                           window[40];
        UInt16                                          formId;
        //FormAttrType                          attr;   // the old
FormAttrType struct was a UInt32
        UInt32                                          attr;
        //WinHandle                             bitsBehindForm;
        void *                                  bitsBehindForm;
        //FormEventHandlerType *        handler;
        void *                                          handler;
        UInt16                                          focus;
        UInt16                                          defaultButton;
        UInt16                                          helpRscId;
        UInt16                                          menuRscId;
        UInt16                                          numObjects;
        //FormObjListType *                     objects;
        struct PrvFormObjList
                {
                //FormObjectKind                        objectType;
                UInt8                                           objectType;
                UInt8                                           reserved;
                //FormObjectType                        object;
                union
                        {
                        void                                    *ptr;
                        } object;
                } *objects;
        } PrvFormType;

/**
 * Get the object index for the current alert.
 *
 * PalmOS prior to v4.0 crashed if object not found in form.
 * Use form structure internals to find object non-fatally.
 *
 * This stuff is here for backward compatibility. It allows compiling on
 * future SDKs, and then deciding to use the stuff at runtime. Otherwise,
 * you have to do different builds, and that's a pain.
 */
static UInt16 PrvFrmGetObjectIndex(const PrvFormType *formP, UInt16 objID)
        {
        struct PrvFormObjList *pObj = formP->objects;
        UInt16 itemIndex = formP->numObjects;

        while (itemIndex--)
                {
                if (*(UInt16*)pObj[itemIndex].object.ptr == objID)
                        return itemIndex;
                }
        return frmInvalidObjectId;
        }

/**
 * Install system hacks/patches.
 *
 */
static void PrvInstallPatches(void)
        {
        UInt32 romVersion;

        FtrGet(sysFtrCreator,sysFtrNumROMVersion,&romVersion);
        if (romVersion < sysMakeROMVersion(4,0,0,sysROMStageDevelopment,0))
                {
        
SysSetTrapAddress(sysTrapFrmGetObjectIndex,(void*)PrvFrmGetObjectIndex);
                }
        }

 

--------------------
Jeff Loucks
Work 425-284-1128 [EMAIL PROTECTED]
Mobile 253-691-8812 [EMAIL PROTECTED]
Home 253-851-8908 [EMAIL PROTECTED]
 

-----Original Message-----
From: Geoffrey [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 24, 2004 10:34 PM
To: Palm Developer Forum
Subject: FrmGetObjectIndex problem

Hi all,

I got a form with some dynamically created objects.
When I use FrmGetObjectIndex in TT (and os5 simurator), when there are no
such object ID (the object doesn't exist), it will return frmInvalidObjectId
(equal = -1).

But when I do the same things in Clie N610 (which is os4), it will return
65535.

Finally, if I ran the program in Palm V (os3.2), it will return an fatal
error said the object doesn't exist.


I want to use FrmGetObjectIndex to see if the object exist, is there any way
to do it in all different version of palmos?

Thank's for your advice.

Geoffrey



-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to