This Question is Answered

1 "correct" answer available (5 pts) 14 "helpful" answers available (3 pts)
2 Replies Last post: Nov 5, 2007 5:51 PM by Tony

How can the sub-contol know the exact type of the parent ?

Nov 4, 2007 11:46 PM

Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007

Parent property of control returns the graphical parent , but the return type is Box. How can I know the exact type of the parent at the runtime.


Click to view rhh's profile Curl rhh 29 posts since
Oct 12, 2007
1. Re: How can the sub-contol know the exact type of the parent ? Nov 5, 2007 3:36 PM
Generally it's better not to build an application where the operation of a control depends on the type of its parent container, because it causes different operation in situations that are visually indistinguishable, such as when you put a control in a Frame that is in turn a child of a parent container, so that options or margins can be set on the Frame. But if you do start with a graphical object g and you navigate to its parent object using an expression such as g.parent, you can determine the run-time type of the parent by using the expression

{type-of g.parent}

You may also want to use the "isa" operator to ask whether the object has a specific type that you're interested in, or the type-switch operator to dispatch to several different handlers depending on the type of the object.

-Bert
Click to view Tony's profile Level 2 Tony 26 posts since
Oct 17, 2007
2. Re: How can the sub-contol know the exact type of the parent ? Nov 5, 2007 5:51 PM
in response to: rhh
Ok, Thanks a lot:8}