[Gambas-user] Object.Class with forms

Benoit Minisini gambas at ...1...
Wed Nov 2 15:16:05 CET 2005


On Wednesday 02 November 2005 14:11, Dani Santos wrote:
> Hi again!
>
> I've got to test wether a control is or not a form.
>
> I've made it work perfectly with TextBoxes, Labels, etc. with code like
> this:
>
>   SELECT CASE Object.Class(pControl)
>
>   CASE "Label"
>     labelTmp = pControl
>     labelTmp.BackColor = COLOR_TITULOS
>     labelTmp.ForeColor = COLOR_TEXTOTITULOS
>   CASE "Button"
>     buttonTmp = pControl
> 	(...)
>
> But If I try to do it with forms, i.e. something like:
>
>   ' Getting the parent form and attaching to the object for resizing
>   ' purposes.
>   m_intParentWidth = m_table.Parent.Width
>   parentForm = m_table.Parent
>   DO WHILE parentForm <> NULL
>
>     IF Object.Class(parentForm) = "Form" THEN
>       Object.Attach(parentForm, ME, "ParentForm")
>       BREAK
>     ELSE
>       parentForm = parentForm.Parent
>     ENDIF
>   LOOP
>
> ObjectClass does not return "Form" for a Form object but "FrmMain",
> "FrmSelectTheme", etc. i.e., the name of the form.
>
> ¿Any idea about how knowing if a given control is a Form?
>
> Thanks.

Since Gambas 1.9.20, you have Object.Is(...) that allows you to test if an 
object is a specific class or one of its children.

Before this version, you can simply do that:

DIM hForm AS Form

TRY hForm = myObject
IF ERROR THEN
  PRINT "This is not a form"
ELSE
  PRINT "This is a form"
ENDIF

Regards,

-- 
Benoit Minisini





More information about the User mailing list