Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
THISFORM.DoAll function similar to THISFORM.SetAll
Message
From
30/12/1998 16:38:00
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00171476
Message ID:
00171732
Views:
29
>>Hi Klas,
>>
>>>Is there some way I can run a method for all controls on a form who are part of a class ... in the same way I can set a property on all controls on a form who are part of a class?
>>>
>>>THISFORM.DoAll("Refresh","MyClass") ????
>>
>>Check out SetAllX from Ken Levy on www.classx.com. I think it can do this.
>>
>>Christof
>
>
>Thanks.
>
>I will take a look at the site as soon at is is available to browse.

Klas, my base form class has a method to do this
PROCEDURE RunAll
lPara tcMethod, toContainer

LOCAL lcMethod, loContainer, loControl, loPage, loColumn, lcSetExact

IF TYPE('tcMethod') <> "C"
	RETURN .F.
ELSE
	lcMethod = tcMethod
ENDIF

* If no container object was passed in, assume that 
* we are running all methods in THIS
IF TYPE("toContainer.Name") <> "C"
	loContainer = THIS
ELSE
	loContainer = toContainer
ENDIF

* I found I needed to set exact on to make sure pages weren't mistaken for pageframes and vice-versa
lcSetExact = SET('EXACT')
SET EXACT ON

* this method only works for container-type classes
IF !INLIST(LOWER(loContainer.BaseClass), "form","container","pageframe","page","grid","column")
	RETURN .F.
ENDIF

DO CASE
	CASE INLIST(LOWER(loContainer.BaseClass),"form","container","page","column")
		FOR EACH loControl IN loContainer.Controls
			* Does the control have the method passed in?
			IF PEMSTATUS(loControl, lcMethod, 5)
				loControl.&lcMethod()
			ENDIF
			* if the control is a container itself, recurse back into this method to drill down into its controls
			IF INLIST(LOWER(loControl.BaseClass), "form","container","pageframe","page","grid","column")
				THIS.RunAll(lcMethod, loControl)
			ENDIF
		ENDFOR

	* I am really doing the same hing for all three of these container types,
	* but the controls collection is called something different in each of them,
	* so I had to separate them out,
	CASE LOWER(loContainer.BaseClass) = "pageframe"
		* For pageframes, iterate through the pages collection
		FOR EACH loPage IN loContainer.Pages
			IF PEMSTATUS(loPage, lcMethod, 5)
				loPage.&lcMethod()
			ENDIF
			THIS.RunAll(lcMethod, loPage)
		ENDFOR
		
	CASE LOWER(loContainer.BaseClass) = "grid"
		* For grids, iterate through the columns collection
		FOR EACH loColumn IN loContainer.Columns
			IF PEMSTATUS(loColumn, lcMethod, 5)
				loColumn.&lcMethod()
			ENDIF
			THIS.RunAll(lcMethod, loColumn)
		ENDFOR
ENDCASE

SET EXACT &lcSetExact
ENDPROC
I did not write in a provision for calling only certain classes. That would be pretty easy to do if you wanted to do it yourself though.
Erik Moore
Clientelligence
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform