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!

How to programmatically find out the complete Position of any object ?

Status
Not open for further replies.

TedMcCoin

Programmer
Feb 19, 2003
14
0
0
DE
this is a general Question of Programming.

eg: there are 2 CommandButtons with the same name on 2 different locations of a given large form:

myFormSTART.PageFrame1.page1.PageFrame1.page1.CommandButton1
myFormSTART.PageFrame1.page1.CommandButton1


THIS.NAME returns just "CommandButton1" rather than the desired structure "myFormSTART.PageFrame1.page1.PageFrame1.page1.CommandButton1"

".Parent." wouldn't really be helpful since the object could be placed deep in the forms structure.


2nd part of my Question is, how to find the full position of a known unique name of an Object, I just know the objects.name but not where it is placed within the form ?

Any Ideas ?
 
I'll have to think about part 2 of your question, but one answer to part 1 is:

SYS(1272, THIS)

Jim
 
Hi Ted.

>> 2nd part of my Question is, how to find the full position of a known unique name of an Object, I just know the objects.name but not where it is placed within the form ? <<

I do not understand what you mean by this. Are you talking about the object's absolute position relative to its form? If this is the case, check out the OBJTOCLIENT() function in the on-line help.



Marcia G. Akins
 
Jim, thanks a lot! That was exactly what I was looking for !

Marcia, thanks for the interesting OBJTOCLIENT()
but that's not what I am looking for. So, to clarify the 2nd part:
Is it possible to programmatically lookup a large form for the existance of a given object, eg myCommandButton and if it exists, where it is placed on a form ?

Thanks for help, Ted
 
Ted,

Let's see if we can clarify this. You have a form containing arbitrary pages, containers, grids, etc. Somewhere in that containership hierarchy is a control, let's say a button named MyCommandButton. You want to locate that button, that is, you want to get an object reference to it so that you can access any of its properties or methods. Is that a correct statement of the problem?

If so, the only way I know is to write a recursive routine which loops through all the controls in the form, then all the controls within the containers on the form (for example, a page frame is a container), then all the controls in the containers' containers, and so on.

Starting with VFP 7.0, all containers (including forms) have a property called Objects, which contains a collection of all the controls in the container. Your recursive routine can loop through the objects collection, looking at each control in turn. As it does so, it test the Name property to see if it contains "MyCommandButton".

I hope this answers your question.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Thanks Mike,

yes, what you suggest above would certainly do what I was looking for :)

Since I still work on VFP version 6.0 I can't check it out yet, however the VFP 8.0 box is already on my desk, almost ready to be checkéd out.

Thanks again,

Ted
 
Ted,

It's also possible do what I suggested with VFP 6.0, but it's much easier in 8.0. In 6.0, most containers do not have an Objects collection, but they do have other kinds of collections. For example, pageframes have a Pages collection; pages have a Controls collection; and so on.

So, you could write recursive code to loop through the collections in 6.0. But you would have to check the base class of each control to decide which of the collections to use.

It's very much easier in 8.0 (and 7.0), so if your requirement isn't urgent, you are right to postpone it.

Let us know how you get on with this.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top