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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Objects properties 3

Status
Not open for further replies.

wrov

Programmer
Nov 1, 2002
43
PY
Hello everybody

There is some way of know which objects are in a form ? I want to know the name and the class of each object for change his properties.

By example:
- To change the forecolor of all labels to blue and the backcolor of all textboxs to white

Thanks in advance

Walter.
 
Just step through the controls on the form
using the controlcount and controls array properties,
which are part of every form.

Example:


* Assuming this code is run from a method
* called ChkClass_And_Name on the form itself.


*//PR: PROCEDURE ChkClass_And_Name
* PURPOSE Step through all controls
* on the form and if they meet
* the criteria we've set for
* being changed - change them.

procedure ChkClass_And_Name
with this
for i = 1 to .controlcount
do case
case .controls(i).class = "Label" .and. .IsInNameList(.controls(i).name)
.controls(i).forecolor = rgb(0,0,255)
case .controls(i).class = "Textbox" .and. .IsInNameList(.controls(i).name)

.controls(i).backcolor = rbg(255,255,255)

* Other case statements if needed
case ...
case ...

otherwise
* default action
endcase
next
endwith
endproc


*//FN: FUNCTION IsInNameList
* PURPOSE Determine if a controls name
* is in the list we want to manage

* This function pre-supposes you've setup an array
* that contains the names of the controls
* you want to change properties for.

* You could just as easily performed the test
* in the case statements of ChkClass_And_Name,
* but if the test gets more complicated it's
* best to separate it out into a function. Which
* of course keeps the code clean.

function IsInNameList(lcControlName)
local lbIsInList
lbIsInList = ascan(this.aControlNamesToChange,lcControlName) <> 0
return lbIsInList
endfunc
'We all must do the hard bits so when we get bit we know where to bite' :)
 
Hi

1. To change the forecolor of all labels to blue and the backcolor of all textboxs to white

ThisForm.SetAll(&quot;ForeColor&quot;,RGB(0,0,128),&quot;Label&quot;)
ThisForm.SetAll(&quot;BackColor&quot;,RGB(255,255,255),&quot;TextBox&quot;)

So this does not require you to go thru all the onjects.

2. However... to scan thru all the controls in your form..
Example..

LOCAL oThis
FOR EACH oThis IN ThisForm.controls
DO CASE
CASE UPPER(m.oThis.BaseClass) == 'LABEL'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'TEXTBOX'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'COMMANDBUTTON'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'EDITBOX'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'COMBOBOX'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'CONTAINER'
WAIT WINDOW oThis.name
** Do whatever
CASE UPPER(m.oThis.BaseClass) == 'PAGEFRAME'
LOCAL oPage
FOR EACH oPage IN m.oThis.Pages
WAIT WINDOW oPage.name
** Do whatever
ENDFOR
CASE UPPER(m.oThis.BaseClass) == 'GRID'
LOCAL oColumn
FOR EACH oColumn IN m.oThis.Columns
WAIT WINDOW oColumn.name
** Do whatever
ENDFOR
CASE UPPER(m.oThis.BaseClass) $ ;
'COMMANDGROUP,OPTIONGROUP'
LOCAL oButton
FOR EACH oButton IN m.oThis.Buttons
WAIT WINDOW oButton.name
** Do whatever
ENDFOR
ENDCASE
ENDFOR
The above is an example.. AND NOT EXHAUSTIVE OF ALL BASE CLASSES how you can loop thru each object..
:)
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
:)SEASONS GREETINGS :) MERRY CHRISTMAS :) HAPPY NEW YEAR :)
 
Ramani's second method is better since a For each loop is faster than the For Next loop I used.

If the form is very congested this could make a difference.

Also, he's right to use the baseclass opposed to the class property, as you may have subclassed the controls and named them something specific. i.e. define class myLabel as Label.

In that case, the code I wrote would fail by omission every time.

Darrell 'We all must do the hard bits so when we get bit we know where to bite' :)
 
To make it more robust, use the PEMSTATUS function to check if a property is there before you use it.

I used to use this fucntion to have all properties in a cursor of an object during runtime.

I just started my 'Inspector' app and put the mouse pointer on an object. Using the PEMSTATUS and several other functions I was able to retrieve all properties, functions and their values of the selected object at runtime.


Just a little addition to the other code given by the VFP 'Gurus' ;-)

Cheers,

Weedz (Edward W.F. Veld)
My private project:Download the CrownBase source code !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top