From lechner@cs.uml.edu Wed Sep 20 18:18:13 2006 Received: from saturn.cs.uml.edu (saturn.cs.uml.edu [129.63.8.2]) by earth.cs.uml.edu (8.12.11.20060308/8.11.6) with ESMTP id k8KMIDMx019741 for ; Wed, 20 Sep 2006 18:18:13 -0400 Received: from saturn.cs.uml.edu (localhost [127.0.0.1]) by saturn.cs.uml.edu (8.12.9/8.12.9) with ESMTP id k8KMKSlh206965 for ; Wed, 20 Sep 2006 18:20:28 -0400 (EDT) Received: (from lechner@localhost) by saturn.cs.uml.edu (8.12.9/8.12.9/Submit) id k8KMKSl2206590 for lechner; Wed, 20 Sep 2006 18:20:28 -0400 (EDT) From: Bob Lechner Message-Id: <200609202220.k8KMKSl2206590@saturn.cs.uml.edu> Subject: Fox alt to bde hasType to Check type of a widget (dynamic cast in fox) To: lechner@cs.uml.edu (Bob Lechner) Date: Wed, 20 Sep 2006 18:20:28 -0400 (EDT) X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Length: 2083 Lines: 61 X-Status: X-Keywords: X-UID: 1207 X-Evolution: 00000660-0000 Status: RO This may be useful on a bde graphobject display (List) class item, to see if it is in the graph, node, caption or hlink subclass. Right now bde/src uses macro hasType(id,XX) below. (267 calls or comments, including assert(hasType(...) checks.) This is analogous to fox's isMemberOf(...) below. hasType is application-independent, like dprint: ------ mercury(16)> grep '#define hasType' ../pr_util_nolog/9*.h 792:#define hasType(key, ttabbr) \ ((&key)?(strstr(decode_retstr(&key),#ttabbr)?1:0):0) -------- decode_retstr looks up a ttabbr at an index and does a string compare. But (&key)==encode(ttabbr) is slower since encode serialy searches for ttabbr in a list of string values. The polymorphic list at topobject->subobjects[->next...] was never dis-aggregated into subtype lists. The pr_loaded VMNetDB segregates types in bde's component hierarchy. This is more faithful to bde's [relational] data model. R Lechner Forwarded message: > From foxgui-users-bounces@lists.sourceforge.net Tue Sep 19 22:16:47 2006 > To: foxgui-users@lists.sourceforge.net > Cc: The Devils Jester > Subject: Re: [Foxgui-users] Check what type a widget is? > > On Tuesday 19 September 2006 19:57, The Devils Jester wrote: > > What is the proper method of checking to see what class a specific widget= > is? > > (I.E. I need to determine if its a button or a toggle button, etc...) > > > Even so, for general reference: > > if(window->isMemberOf(FXMETACLASS(ClassName))){ > ... > } > > This would work; however, the C++ way is better: > > ClassName *someclass=dynamic_cast(window); > if(someclass){ > ... > } > > > This is language-supported, and since you usually want to know > what class something is in order to cast the pointer, it kills > two birds with one stone, so to speak. > > Apart from that, a C++ style cast takes care of potential multiple- > inheritance issues [not that this is relevant inside FOX itself, > which is strictly single-inheritance; however it may be an issue > in your own classes]. > > - Jeroen