Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP 6.0: recurring procedure on Form.Objects?

Status
Not open for further replies.

Kimed

Programmer
May 25, 2005
104
LT
Hi,

I need to perform a certain operation on all objects that a form contains (and no, SetAll method won't suffice). For this, I created a following method:

Code:
PROCEDURE recurfunc
PARAMETERS targetname as String
PRIVATE member as Object 

&& ( the operation itself )

IF TYPE(targetname+".Objects")="O"
	FOR EACH member IN (targetname+".Objects")
		thisform.recurfunc(targetname+"."+member.name)
	ENDFOR
ENDIF
, called with the command thisform.recurfunc("thisform"). In theory, any "branch" object that has an object list of its own (the form itself, page frames, grids, etc.) would call the same method with its full path as a parameter, while the "leaf" objects wouldn't.

Contrary to my expectations, TYPE("thisform.Objects") returned "U" instead of "O" to me (even though the form object, naturally, *has* an Objects property), making distinction between containers and non-containers impossible. If I delete the checking, recursion works okay but only until it reaches a leaf.

What am I doing wrong and how can I achieve what I need?

Thanks.
 
Instead of TYPE(targetname+".Objects")="O", try testing PEMSTATUS(loObject, "objects", 5 ). This will return .T. if the object in question has an Objects property, indicating that it is a container (where loObject is the relevant object reference).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
And when you use Recursive functions/methods make sure that ALL variables used in it is defined as LOCAL and send object.
Code:
PROCEDURE recurfunc
LPARAMETERS targetname as OBJECT
LOCAL member as Object 

IF PAMSTATUS(targetnamem "Objects", 5)
   FOR EACH member IN (targetname.Objects)
       thisform.recurfunc(member)
   ENDFOR
ENDIF

Borislav Borissov
VFP9 SP2, SQL Server
 
You have a procedure recurfunc, is that a method of the form or a procedure defined in a prg external to the form?

THISFORM is a reference only valid in code of the form or of it's objects, that's all. execute ? TYPE("THISFORM") at the command window and you get "U", of course. run it in any method of a form and you get "O". Run it in a prg and you get "U". If THISFORM is not defined in the context of the code you run, obviouls also all other sub objects can't be defined.

You could stay with your code, if you just make it a method of the form or your base form class to let any form inherit it.

You just have to pay more attention to the scope of things, that's all.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top