 | | From: | Heinz Kesting | | Subject: | How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 19:57:07 +0100 |
|
|
 | Hi everybody, In an OPEN evnt of a form I need to loop through ALL form objects. I copied the example from the OLH given for the property "before". This works only for the objects on the "top level" of the form, but not for the objects that are nested on a notebook or in a container. The notebook itself is found, but texts or pushbuttons on that notebook are ignored. Here's the code:
local obj obj = form.first // First control in z-order ? "obj.classname = " + obj.classname // for testing ? "obj.name = " + obj.name // for testing ? type('obj.fontsize') // for testing ? obj.fontsize // for testing if type('obj.fontItalic') = 'L' // check for a fontItalic property obj.fontItalic = false ? "obj.classname = " + obj.classname // for testing ? "obj.name = " + obj.name // for testing endif obj := obj.before // Next control in z-order do while obj # form.first if type('obj.fontItalic') = 'L' // check for a fontItalic property obj.fontItalic = false ? "obj.classname = " + obj.classname // for testing ? "obj.name = " + obj.name // for testing endif obj := obj.before // Next control in z-order enddo
How can the objects "within" other objects (like notebooks or containers) be found? The loop is to switch fontItalic from TRUE to FALSE in certain situations. To leave out the objects that don't have a fontItalic property I tried with the line if type('obj.fontItalic') = 'L' but that is always returning "U", as well as ? type('obj.fontsize'), while ? obj.fontsize or ? obj.fontItalic responds as expected at the same time. There must be an error in this, but I can't see it ...
Any help appreciated!
Best regards, Heinz
|
|
 | | From: | Michael Nuwer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 14:35:34 -0500 |
|
|
 | Heinz Kesting wrote: > Hi everybody, > In an OPEN evnt of a form I need to loop through ALL form objects. I copied > the example from the OLH given for the property "before". > This works only for the objects on the "top level" of the form, but not for > the objects that are nested on a notebook or in a container. The notebook > itself is found, but texts or pushbuttons on that notebook are ignored. > Here's the code: > > local obj > obj = form.first // First control in z-order > ? "obj.classname = " + obj.classname // for testing > ? "obj.name = " + obj.name // for testing > ? type('obj.fontsize') // for testing > ? obj.fontsize // for testing > if type('obj.fontItalic') = 'L' // check for a fontItalic property > obj.fontItalic = false > ? "obj.classname = " + obj.classname // for testing > ? "obj.name = " + obj.name // for testing > endif > obj := obj.before // Next control in z-order > do while obj # form.first > if type('obj.fontItalic') = 'L' // check for a fontItalic property > obj.fontItalic = false > ? "obj.classname = " + obj.classname // for testing > ? "obj.name = " + obj.name // for testing > endif > obj := obj.before // Next control in z-order > enddo > > How can the objects "within" other objects (like notebooks or containers) be > found?
The following is from :duflp:formstuf.prg It should do what you need with a few modification. The function loops through child objects by calling itself -- so it must be a function.
/* Enable Controls -- this will loop through all controls on a form and set their enabled property to true or false depending on the parameters you pass it.
Author: Jim Sare Posted on the VdBASE Newsgroups, 7/9/1998
Usage Notes:
This particular method enables/disables all controls in the form and any containers on the form. It can be adapted to other purposes.
To use it:
Copy the method into the form class (before the ENDCLASS statement)
FORM.EnableControls( false ) // disable all controls FORM.EnableControls( true ) // enable all controls FORM.EnableControls( false, FORM.Notebook1 ) // disable all controls ONLY // on Notebook1 FORM.EnableControls( true, FORM.Notebook1 ) // enable all controls ONLY // on Notebook1 These last two commands can be used for a container as well.
The function is recursive so if a container contains controls and another container or notebook, the controls contained in those containers and/or notebooks will also be affected.
*/ PROCEDURE EnableControls parameters lEnable, o private oRef local oParent
oParent = iif( type( "o" ) == "O", o, FORM ) oRef = oParent.first do if type( "oRef.first" ) == "O" form.EnableControls( lEnable, oRef ) endif if type( "oRef.Enabled" ) # "U" oRef.Enabled:= lEnable endif oRef = oRef.before until oRef.Name == oParent.first.name
// End of EnableControls()
|
|
 | | From: | Todd Kreuter [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 15:35:47 -0500 |
|
|
 | "Michael Nuwer [dBVIPS]" wrote: > > The following is from :duflp:formstuf.prg It should do what you need > with a few modification. The function loops through child objects by > calling itself -- so it must be a function.
Pretty slick. Wish I knew of this before. I remember losing a couple hours of sleep trying to write my own routine. ;-)
-- Todd Kreuter [dBVIPS]
|
|
 | | From: | Michael Nuwer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 16:07:35 -0500 |
|
|
 | Todd Kreuter [dBVIPS] wrote:
> "Michael Nuwer [dBVIPS]" wrote: > >>The following is from :duflp:formstuf.prg It should do what you need >>with a few modification. The function loops through child objects by >>calling itself -- so it must be a function. > > > Pretty slick. Wish I knew of this before. I remember losing a couple > hours of sleep trying to write my own routine. ;-)
The challenge is first learning all that is in the dUFLP and then remembering that its there. I (and Heinz) just got lucky this time. :-)
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 23:40:44 +0100 |
|
|
 | Hi Michael > > The challenge is first learning all that is in the dUFLP and then > remembering that its there. I (and Heinz) just got lucky this time. :-)
Well, I'm really lucky to find here this big amount of support in such a friendly atmosphere. By the way, I actually find it not that easy to seek something in the dUFLP - the library.wfm isn't really "user friendly", is it?
Thanks anyway, Heinz
|
|
 | | From: | Michael Nuwer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 06:56:19 -0500 |
|
|
 | Heinz Kesting wrote:
> Well, I'm really lucky to find here this big amount of support in such a > friendly atmosphere.
Yes, this is a great bunch of people.
> By the way, I actually find it not that easy to seek something in the > dUFLP - the library.wfm isn't really "user friendly", is it?
Reading the file headers is the way I've approached it. And if you have third party editor that will search multiple text files, that works too.
-- Michael Nuwer http://www.nuwermj.potsdam.edu/dLearn/ http://www.nuwermj.potsdam.edu/dSamples/
"I would rather be vaguely right, than precisely wrong." -- John Maynard Keynes
|
|
 | | From: | Todd Kreuter [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 18:03:14 -0500 |
|
|
 | Heinz Kesting wrote: > > Well, I'm really lucky to find here this big amount of support in such a > friendly atmosphere. > By the way, I actually find it not that easy to seek something in the > dUFLP - the library.wfm isn't really "user friendly", is it?
There is a libary form you can use to search...
-- Todd Kreuter [dBVIPS]
|
|
 | | From: | Ken Mayer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 05:27:33 -0800 |
|
|
 | Heinz Kesting wrote: > Hi Michael > >>The challenge is first learning all that is in the dUFLP and then >>remembering that its there. I (and Heinz) just got lucky this time. :-) > > > Well, I'm really lucky to find here this big amount of support in such a > friendly atmosphere. > By the way, I actually find it not that easy to seek something in the > dUFLP - the library.wfm isn't really "user friendly", is it?
Have you tried the second page? If you would like to create a new, more user-friendly version of "library.wfm", please feel free ...
Ken
-- /(Opinions expressed are purely my own, not those of dataBased Intelligence, Inc.)/
*Ken Mayer* [dBVIPS] /Golden Stag Productions/ dBASE at goldenstag dot net http://www.goldenstag.net/GSP http://www.goldenstag.net/dbase
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 19:19:11 +0100 |
|
|
 | Hi Ken
> Have you tried the second page? If you would like to create a new, more > user-friendly version of "library.wfm", please feel free ...
If I would be able to do this, I'd certainly do, but with my momentary knowledge it would not be to the better of it, I'm afraid. I tried the second page, of course, but I wish there could be a possibilty to search memo fields ...
Thanks, Heinz
|
|
 | | From: | Ken Mayer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 10:53:05 -0800 |
|
|
 | Heinz Kesting wrote: > Hi Ken > > >>Have you tried the second page? If you would like to create a new, more >>user-friendly version of "library.wfm", please feel free ... > > > If I would be able to do this, I'd certainly do, but with my momentary > knowledge it would not be to the better of it, I'm afraid. I tried the > second page, of course, but I wish there could be a possibilty to search > memo fields ...
Actually, the second page of the library form *does* search memo fields. Try it ... the checkbox to search in the description (which is a memo field) allows this.
Ken
-- /(Opinions expressed are purely my own, not those of dataBased Intelligence, Inc.)/
*Ken Mayer* [dBVIPS] /Golden Stag Productions/ dBASE at goldenstag dot net http://www.goldenstag.net/GSP http://www.goldenstag.net/dbase
|
|
 | | From: | Todd Kreuter [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 16:47:41 -0500 |
|
|
 | "Michael Nuwer [dBVIPS]" wrote: > > The challenge is first learning all that is in the dUFLP and then > remembering that its there. I (and Heinz) just got lucky this time. :-)
The latter being the most challenging ;-)
-- Todd Kreuter [dBVIPS]
|
|
 | | From: | Ken Mayer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 05:26:49 -0800 |
|
|
 | Todd Kreuter [dBVIPS] wrote: > "Michael Nuwer [dBVIPS]" wrote: > >>The challenge is first learning all that is in the dUFLP and then >>remembering that its there. I (and Heinz) just got lucky this time. :-) > > > The latter being the most challenging ;-) >
Shoot, I am the librarian for this thing, and I can't remember everything in it ...
Ken
-- /(Opinions expressed are purely my own, not those of dataBased Intelligence, Inc.)/
*Ken Mayer* [dBVIPS] /Golden Stag Productions/ dBASE at goldenstag dot net http://www.goldenstag.net/GSP http://www.goldenstag.net/dbase
|
|
 | | From: | Todd Kreuter [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Thu, 20 Jan 2005 08:53:46 -0500 |
|
|
 | "Ken Mayer [dBVIPS]" wrote: > > Shoot, I am the librarian for this thing, and I can't remember > everything in it ...
;-)
-- Todd Kreuter [dBVIPS]
|
|
 | | From: | Heinz Kesting | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 21:02:13 +0100 |
|
|
 | Hi Michael, > The following is from :duflp:formstuf.prg It should do what you need > with a few modification. The function loops through child objects by > calling itself -- so it must be a function.
Great, that will do the trick! It's exactly what I was looking for! As to my other problem about the type() problem I played meanwhile with macro substitution, but failed as well ...
private obj obj = form.first // First control in z-order ? "obj.classname = " + obj.classname ? "obj.name = " + obj.name ? 'type("form.txt_head.fontItalic") = ' + type("&obj..fontItalic") // still returns: U ? obj.fontItalic // while this is TRUE resp. FALSE
Any ideas?
Thanks, Heinz
|
|
 | | From: | Michael Nuwer [dBVIPS] | | Subject: | Re: How to loop through ALL form objects | | Date: | Wed, 19 Jan 2005 16:00:11 -0500 |
|
|
 | Heinz Kesting wrote: > Hi Michael, > >>The following is from :duflp:formstuf.prg It should do what you need >>with a few modification. The function loops through child objects by >>calling itself -- so it must be a function. > > > Great, that will do the trick! It's exactly what I was looking for! > As to my other problem about the type() problem I played meanwhile with > macro substitution, but failed as well ... >
The sample form below seems to work for me. When you use the type() function -- in the code you posted in the first message of this thread -- be sure the "obj" variable is private, not local, as type() doesn't work with locals.
// // Generated on 01/19/2005 // parameter bModal local f f = new testerForm() if (bModal) f.mdi = false // ensure not MDI f.readModal() else f.open() endif
class testerForm of FORM with (this) onOpen = class::FORM_ONOPEN height = 10.0455 left = 52.0 top = 0.0 width = 40.0 text = "" endwith
this.ENTRYFIELD1 = new ENTRYFIELD(this) with (this.ENTRYFIELD1) height = 1.0 left = 10.0 top = 1.5 width = 20.0 value = "Entryfield1" endwith
this.CONTAINER1 = new CONTAINER(this) with (this.CONTAINER1) left = 10.0 top = 3.0 width = 20.0 height = 1.5 endwith
function form_onOpen if type("this.container1.fontItalic") == "L" ?this.container1.fontItalic endif if type("this.entryfield1.fontItalic") == "L" ?this.entryfield1.fontItalic endif return
endclass
|
|