Referencing ALL of the controls in a form 
Author Message
 Referencing ALL of the controls in a form

I am stuck trying to reference ALL of the controls on a form in a
basicdataentryform class so that I can add generic tooltiptext for any item
on the form that matches an item in a table.

I am putting something like this in the init of the form class:

    for each x in thisform.controls
        blah blah blah
        if type('x.controlcount')<>'U' && This means it is another container
            need to do another loop the same as this one
        endif
    endfor

Yu can see the problem is that I have many container objects many levels
deep and I can't (won't) make a dozen or so nested loops to potentially
handle them.
Does anyone understand this problem and could suggest something?
Thanks in advance,
Darren Ramsay.



Fri, 02 Apr 2004 04:21:42 GMT  
 Referencing ALL of the controls in a form
If it is a static tooltiptext, consider doing this at design time:

1) MODI FORM yourform
2) Ctrl+F2
3) DO settooltiptext

where settooltiptext.prg contains code similar to this:

     for each x in _vfp.forms(1).controls
         blah blah blah
         if type('x.controlcount')<>'U' && This means it is another container
             need to do another loop the same as this one
         endif
     endfor

4) save your form.

just a thought.

--
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP7

Quote:

> I am stuck trying to reference ALL of the controls on a form in a
> basicdataentryform class so that I can add generic tooltiptext for any item
> on the form that matches an item in a table.

> I am putting something like this in the init of the form class:

>     for each x in thisform.controls
>         blah blah blah
>         if type('x.controlcount')<>'U' && This means it is another container
>             need to do another loop the same as this one
>         endif
>     endfor

> Yu can see the problem is that I have many container objects many levels
> deep and I can't (won't) make a dozen or so nested loops to potentially
> handle them.
> Does anyone understand this problem and could suggest something?
> Thanks in advance,
> Darren Ramsay.



Fri, 02 Apr 2004 13:16:23 GMT  
 Referencing ALL of the controls in a form
Darren,

I can see two possible solutions

(1) thisform.Setall()    && might work, depending on what yiu want to do

(2) if this does not work for you, then add a method to the form/class which
calls itself recursively
in the init call it with: this.Method(this, 'TooltipText', 'the value')

method(obj, PropertyName, PropertyValue)

if( type('obj.&PropertyName) <> T_UNDEFINED )
    obj.&PropertyName = PropertyValue
endif

local ptr, i
do case
case type('obj.ControlCount') <> T_UNDEFINED
    for i = 1 to obj.ControlCount
        ptr = obj.Controls[i]
          =this.Method(ptr)
    endfor
case type('obj.PageCount') <> T_UNDEFINED
    for i = 1 to obj.PageCount
        ptr = obj.Pages[i]
          =this.Method(ptr)
    endfor
case type('obj.ButtonCount) <> T_UNDEFINED
    for i = 1 to obj.ButtonCount
        ptr = obj.Buttons[i]
          =this.Method(ptr)
    endfor

case ... There may be more containers, but the 3 above are all I can think
of

endcase

The If at the beginning could be put in the Otherwise clause of the case,
provided that the PropertyName is never a property of the container class

hth
Gregory
____________


| I am stuck trying to reference ALL of the controls on a form in a
| basicdataentryform class so that I can add generic tooltiptext for any
item
| on the form that matches an item in a table.
|
| I am putting something like this in the init of the form class:
|
|     for each x in thisform.controls
|         blah blah blah
|         if type('x.controlcount')<>'U' && This means it is another
container
|             need to do another loop the same as this one
|         endif
|     endfor
|
| Yu can see the problem is that I have many container objects many levels
| deep and I can't (won't) make a dozen or so nested loops to potentially
| handle them.
| Does anyone understand this problem and could suggest something?
| Thanks in advance,
| Darren Ramsay.
|
|



Fri, 02 Apr 2004 16:23:27 GMT  
 Referencing ALL of the controls in a form
Hi Darren.

Quote:
> Yu can see the problem is that I have many container objects many levels
> deep ...
> Does anyone understand this problem and could suggest something?

See code:
Class Library:  (HOME()+'wizards\wizbtns.vcx')
Class:  txtbtns
method: SetAllProp(oControl)

Best regards.
Michael Drozdov, ICS Soft, Perm, Russia
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My Page:  http://vfpdmur.narod.ru/
ICS Page: http://ics.perm.ru/ [on Russian]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Quote:
> I am stuck trying to reference ALL of the controls on a form in a
> basicdataentryform class so that I can add generic tooltiptext for any
item
> on the form that matches an item in a table.

> I am putting something like this in the init of the form class:

>     for each x in thisform.controls
>         blah blah blah
>         if type('x.controlcount')<>'U' && This means it is another
container
>             need to do another loop the same as this one
>         endif
>     endfor

> Yu can see the problem is that I have many container objects many levels
> deep and I can't (won't) make a dozen or so nested loops to potentially
> handle them.
> Does anyone understand this problem and could suggest something?
> Thanks in advance,
> Darren Ramsay.



Fri, 02 Apr 2004 17:48:56 GMT  
 Referencing ALL of the controls in a form
Hi
Give each control class in you class library a udf property ToolTipID and a
tooltipid_assign event. In the tooltipid_assign code  call some common
method that updates the tooltiptext property. If you need to distinguish
different controls assign each one a different tooltipid number. You can
then call all of the controls with
     Thisform.SetAll(Tooltipid,0)
The ToolTipId_assign code could be like this
     LPARAMETERS newValue
     IF newvalue > 0
         Thisform.ToolTipmanager.SetToolTip(This)
    Endif
and the ToolTipManager.SetToolTip code
  LPARAMETERS oObj
  * code to determine appropropriate tololtip for the object based on its
TooltipId number
   oObj.ToolTipText = ...

SetAll goes into every visible control regardless of its container depth.
-Anders


Quote:
> I am stuck trying to reference ALL of the controls on a form in a
> basicdataentryform class so that I can add generic tooltiptext for any
item
> on the form that matches an item in a table.

> I am putting something like this in the init of the form class:

>     for each x in thisform.controls
>         blah blah blah
>         if type('x.controlcount')<>'U' && This means it is another
container
>             need to do another loop the same as this one
>         endif
>     endfor

> Yu can see the problem is that I have many container objects many levels
> deep and I can't (won't) make a dozen or so nested loops to potentially
> handle them.
> Does anyone understand this problem and could suggest something?
> Thanks in advance,
> Darren Ramsay.



Fri, 02 Apr 2004 16:36:39 GMT  
 Referencing ALL of the controls in a form

Quote:
> I am stuck trying to reference ALL of the controls on a form in a
> basicdataentryform class so that I can add generic tooltiptext for any
> item on the form that matches an item in a table.

> I am putting something like this in the init of the form class:

>     for each x in thisform.controls
>         blah blah blah
>         if type('x.controlcount')<>'U' && This means it is another
>         container
>             need to do another loop the same as this one
>         endif
>     endfor

> Yu can see the problem is that I have many container objects many
> levels deep and I can't (won't) make a dozen or so nested loops to
> potentially handle them.
> Does anyone understand this problem and could suggest something?
> Thanks in advance,
> Darren Ramsay.

This is one of the beautiful (and rare) cases where recursion
is the best (and almost only) solution:

FUNCTION setToolTips
LPARAMETERS toControl

  IF toControl is type of control that gets a tool tip
     set the tooltip accordingly
  ENDIF

  IF toControl is a container of some kind ;
   (form, pageframe, page, container, etc)
     FOR EACH loControl IN toControl.Controls
        setToolTips(loControl)
     ENDIF
  ENDIF

  RETURN

-- TRW
_______________________________________
My e-mail:  t r w 7

_______________________________________



Fri, 02 Apr 2004 23:43:26 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Referencing the controls on a form from another form

2. Referencing a form control from the main.prg

3. reference control on one form from another

4. referencing forms from other forms

5. referencing forms and their objects from other forms

6. Can't reference on forms properties from another form

7. Grid Control Expansive Reference

8. Help with ActiveX control property references

9. Referencing controls in a class

10. Making controls reference the correct class library

11. Referencing Forms in a Formset

12. erroro referencing form object from report

 

 
Powered by phpBB® Forum Software