> I daresay Keith
> could come up with something even better involving templates.  :-)

Well, OK, but only because you asked for it:

template <typename T>
inline T* GetObjPtrAs (FormType* f, UInt16 id)
{
   return static_cast<T*>(FrmGetObjectPtr (f, FrmGetObjectIndex (f, id)));
}


   FieldType*     fred = GetObjPtrAs<FieldType> (form, id_EditField);
   ControlType*   wilma = GetObjPtrAs<ControlType> (form, id_Control);


-- Keith "You, uh, were serious, weren't you, John?"






John Marshall <[EMAIL PROTECTED]> on 11/16/2000 12:14:08 AM

Please respond to "Palm Developer Forum" <[EMAIL PROTECTED]>

Sent by:  John Marshall <[EMAIL PROTECTED]>


To:   "Palm Developer Forum" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/US/PALM)
Subject:  Re: SDK prototype question: FrmSetTitle



Ages ago, Ben Combee <[EMAIL PROTECTED]> wrote:
> any chance of a future SDK having FrmGetObjectPtr
> return a "FormObjectType" rather than the current "void *".  Effectively its
> just a prototype change, but it would make the intent clearer, and avoid
> ugly C++ casting, since you could use the union member to get at the
> appropriate pointer type.

But it would introduce ugly C casting, since you could no longer use
the implicit conversion in

     /* Valid in C only!!  */
     FieldType *field = FrmGetObjectPtr (form, id_EditField);

Of course C programs could use the union member too, but the point is
that existing C source code which assumed that the implicit conversion
would happen would get broken.

Sorry.  No can do.

In my C++ projects, I have a header file with a bunch of functions like

    inline FieldType*
    GetFieldPtr (FormType* f, UInt16 id) {
      return static_cast<FieldType*>(FrmGetObjectPtr (f,
                                              FrmGetObjectIndex (f,id)));
      }

This concentrates all the ugly casting in one place.  I daresay Keith
could come up with something even better involving templates.  :-)

    John  "still looking at FrmSetTitle"

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





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

Reply via email to