[Gambas-user] Object names

Christopher Brian Jack brian at ...1334...
Fri Oct 27 01:27:43 CEST 2006


What I'm looking for is, given any particular Control (passed as client to
the SUB in my example), I'd like to get the name that it was given in the
designer (as per my example of passing the textbox on the form to SomeSub
and inside SomeSub being able to find out that the control now referenced
by the client parameter to SomeSub is called "TextBox1").  I know I can
find out what kind of object it is with the Object static class (in this
example: "TextBox") but I'm unsure about how to find the object's name
("TextBox1" or "RazzleDazzle" if it was so named in the Form Designer).

Unless I'm misunderstanding it, the code below appears to be solving a
different problem.  The code looks more like a way to recursively access
the contents of a form.

So try this again:

Make a form with Button.  I'll go into the designer and change it from
"PushButton1" or whatever default I get and change it to "RazzleDazzle"
and just to further unambiguate I'll make the Text property "Something
Else Altogether" and the Tag "TheseArentTheDroidsYourLookingFor"

Now the sub(s):

PUBLIC SUB GetControlName(client as Control) as String
  DIM sName as String

  sName=?????????? what do I need here ??????????

  return sName
END SUB

Somewhere else in the code:

PUBLIC SUB RazzleDazzle_Click()
  DIM who AS VARIANT=LAST

  PRINT Object.Class(who)
  PRINT GetControlName(who)
END

Clicking the textbox should put in the console the output:
TextBox
RazzleDazzle

The Form should be displaying "Something Else Altogether" in the TextBox
when run.


On Fri, 27 Oct 2006, Charlie Reinl wrote:
>
> Am Donnerstag, den 26.10.2006, 12:09 -0700 schrieb Christopher Brian
> Jack:
> > Say I have a Form with a control, say a textbox that happens to be called
> > TextBox1
> >
> > Now say I have a function of the form:
> >
> > PUBLIC SUB SomeSub(client as Control)
> >
> > ...
> >
> > END
> >
> > Is there any way to find out the client's name (eg: TextBox1)?
> >
> Salut,
>
> dit you think about something like that ?
>
> this is MEditorColors.module
>
> ' Gambas module file
> CONST myGotFocusColor AS Integer  = &HAAFF7F&
> CONST myLostFocusColor AS Integer = &HF9F9BD&
> PUBLIC SUB SetEditColor(oObj AS Object, objLast AS Control)
> DIM myControl AS String
> DIM hClass AS Control
> DIM hCont AS Container
>     myControl = Object.Class(objLast)
>     FOR EACH hClass IN oObj.Children
>       ' is it like my LAST ?
>       IF Object.Class(hClass) = myControl THEN
>         ' only for debugging
>         'PRINT  Object.Class(hClass) & "     LAST.TAG = " & objLast.Tag
> & "          hClass.Tag = "  & hClass.Tag
>         IF objLast.Tag = hClass.Tag THEN
>             hClass.Background = myGotFocusColor
>         ELSE
>             hClass.Background = myLostFocusColor
>         ENDIF
>       ELSE
>         ' TRY if it is a Container
>         TRY hCont = hClass
>         IF NOT ERROR THEN
>             ' I call my self to find out if there are Cildren like my
> LAST
>             SetEditColor(hClass, objLast)
>         ENDIF
>       ENDIF
>     NEXT
> END
>
>
> this is called by :
>
> Public SUB Col_GotFocus()
> 	MEditorColors.SetEditColor(ME, LAST)
> END
>
> May be that gives you an Idea. (It came from gambas1)

.=================================================.
|  Christopher BRIAN Jack aka "Gau of the Veldt"  |
+================================================='
| oevna at ...1544...
`=================================================-
Hi Spambots, my email address is sputnik at ...1334...
Hi Humans, my email address uses rot13 cipher





More information about the User mailing list