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

How to scan all objects and their properties and have them be displayed in an Edit Box 2

Status
Not open for further replies.

JohnDoeVFP

Programmer
Aug 10, 2015
4
0
0
DE
Hello everyone :)

After having spent approximately 4 hours searching the web for usable information, I've decided to ask for help.

I've been trying to scan all objects and all of their properties within a form and have them be printed into an edit box.
Some people seem to recommand using things like DISPLAY OBJECTS or LIST OBJECTS but neither one of those has been working for me thus far.
 
That's about documenting a project, There is PDM (project documenting machine) doing that and much more.
While the output is less optimal for further programmatic analysis it offers all code needed to get every info about every project file.


If you want runtime values, you could call the .SaveAsClass() method to save the current state as a class or traverse each Object In this.OBJECTS with the help of the array AMEMBERS() generates for all members (properties, events, methods).

Bye, Olaf.
 
To visit all the objects, you need to recursively loop though the form's Objects collections. Something like this:

Code:
* VisitControls method. Receives an object reference to the current control.
LPARAMETERS toControl

loContainer = THISFORM
* Perform the required action for the container itself
THIS.Execute(loContainer)

* Loop through the controls in the container
FOR EACH loObject IN loContainer.OBJECTS

  IF PEMSTATUS(loObject, "objects", 5 )
    * Control has an objects collection, so is itself a container;
   * call the method recursively
    THIS.VisitControls(loObject)
  ELSE
* Control is a non-container; perform the specified action
    THIS.Execute(loObject)
  ENDIF
ENDFOR

You then need a method (which I've called Execute) which actually performs some action on each of the controls. In your case, the action would be to use AMEMBERS() to get the properties, methods, etc.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You do know that a form is in fact a table that you can "use"

use myform.scx
browse

or

use myform.scx
list all objname,properties
etc.

(only the set, the not default properties are shown)
 
I should have posted this right away but I need the output( that will be visible in the edit box) to look exactly like the file I included. The fact that it is partially in german is irrelevant though.

There is supposed to be a certain function that will make it so but I've been utterly unable to find any clues
 
 http://files.engineering.com/getfile.aspx?folder=5644096e-eaf4-4af7-bcf1-d53a4e591e6c&file=formobjekt.txt
The code I gave you will get you three quarters of the way there. You just need to add some code of your own in the method that I called Execute. That code should call AMEMBERS() for the current object (the one you pass to Execute as a parameter). You then loop through the array that AMEMBERS() creates. For each item in the array, just add the member name into a string. When finished, set the value of the edit box to that string.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I see you also want to display the value of each of the properties. Something like this should do it:

Code:
LPARAMETERS toObject

AMEMBERS(laMembers, toObject)
lcStr = ""
FOR lnI = 1 TO ALEN(laMembers)
  lcStr = lcStr + laMembers(lnI) + ":" + ; 
    GETPEM(toOBJECT, laMembers(lnI)) + CHR(13) + CHR(10)
ENDFOR 

thisform.EditBox1.Value = lcStr

Note that, if a given member is a method or an event (as opposed to a property), this will display the code in that method or event, which might not be what you want. But that should be easy to fix. I'll leave it to you to do that.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
You're looking for something, which doesn't exist. There is no VFP command, which does that output,
You'll have to roll your own, something along the lines of what Mike gave you, iterating the AMEMBERS of an object and perhaps recursing into child objects via the THIS.OBJECTS array.
You also need special care about ACTIVEFORM, ACTIVECONTROL, these might not be set and therefor trying to GETPEM them would error. Also reading PARENT is unnecessary, it could put a recursive algorithm to an infinite loop, as you go up the containment chain of object containments.


Bye, Olaf.
 
Thank you for all of your advice.

I've almost completed my little project at this point. The only thing I still seem to struggle with is the counting of the amount of objects aswell as getting the actual values of the properties I'm displaying.

Edit: I'm sorry for asking such stupid questions. I've been programming for maybe 1 to 2 months and the only language I have been using till now was JS(on a very basic level) so I've been struggling a fair bit to just understand some of the code you guys have posted.
 
John,

You don't need to apologise for asking "stupid" questions - which are not stupid at all. However, it would help if you could tell us which of our suggestions you have tried, and whether they are working for you. I showed how to get the value of the properties in my second code example. Did you try that? And, if so, what went wrong with it?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

In your second example one must test the type of the returned property before it can be added to lcStr
I don't know if that's obvious for someone who is only 2 month programming in VFP.

Example
Code:
   vv= GETPEM(TOoBJECT, laMembers(lnI))
   
   if type('vv')='L'
	lcstr=lcstr+iif(vv,'True','False') + CHR(13) + CHR(10)
   endif	
   if type('vv')='N'
	lcstr=lcstr+str(vv) + CHR(13) + CHR(10)
   endif	
   if type('vv')='C'
	lcstr=lcstr+vv + CHR(13) + CHR(10)
   endif
 
Thank you everyone!
The solution I came up with is:

Code:
 DECLARE ObjectArray[3]
objectarray[1] = thisform.edit1
objectarray[2] = thisform.command1
objectarray[3] = thisform.command2
lcStr = ""
lbrk = CHR(13) + CHR(10) 


lcStr = lcStr + "Anzahl Objekte: "+ALLTRIM(STR(ALEN(ObjectArray)))+ lbrk 

FOR n = 1 TO ALEN(ObjectArray)
lcStr = lcStr + "-------------------------------------------------------------" + lbrk 
lcStr =lcStr + "Objektklasse: "+ObjectArray[n].class + lbrk 
lcStr =lcStr + "Objektname: " + ObjectArray[n].name + lbrk 
lcStr =lcStr + "Eigenschaften/Werte:" + lbrk 

	AMEMBERS(PropArray, objectarray[n])
	FOR i = 1 TO ALEN(PropArray)
		propvalue = TRANSFORM(GETPEM(objectarray[n], PropArray(i)))
		lcStr =lcStr + "	" +PropArray(i)+ ": "+ propvalue  + lbrk  
 		
	ENDFOR 
ENDFOR 
thisform.Edit1.Value = lcStr

I know it's far from perfect but it does what I wanted to achieve.
Again, thank you for your answers :)
 
For the sake of universal usability the function should rather just return the lcStr value and the calling method or function should then fill this in the editbox.
If you put that into a PRG and begin with a single object in objectarray[1] = _SCREEN you'll see some problems popping up because of special _screen properties. Some of them are in any form, too.

But otherwise it's quite ok.

Bye, Olaf.
 
Looks good to me.

Just a couple of small suggestions:

Instead of [tt]ALLTRIM(STR(ALEN(ObjectArray)))[/tt], I would do [tt]TRANSFORM(ALEN(ObjectArray))[/tt]. The effect is the same, but the latter is little more concise.

And, given that you are accessing ALEN(ObjectArray) many times (each time round the FOR loop), I'd probably store it in a variable and reference it from there. In other words:

Code:
lnCount = ALEN(ObjectArray)
lcStr = lcStr + "Anzahl Objekte: "+ TRANSFORM(lnCount) + lbrk 
FOR n = 1 TO lnCount
  etc. etc.
ENDFOR

These really are minor points, and I only mention them because I know you are just starting out with VFP, so I hope this will help build up your knowledge.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top