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

Container Class Property/Method

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
With VFP9
I'm creating a container class "myContainer" which contains 3 labels: myLabel1, myLabel2 etc. The initial captions are set to "Title" and the 3 labels are arranged and colored so as to provide a 3D appearance.

I've added a new property "myFormTitle" with an initial value of "Title".

After dropping the class on a form, I'd like for the 3 labels to inherit any changes to the myFormTitle property.

Is it possible to place code similar to the following some place where the changes would take place in realtime while in the form designer?

myContainer.myLabel1.caption = myContainer.title
myContainer.myLabel2.caption = myContainer.title.
myContainer.myLabel3.caption = myContainer.title.

I tried the GotFocus() of the container with no luck.

Thanks in advance for your suggestions. Feel free to tell me a better way to do this.

CDavis
 
CDavis,

Just to be clear: You want to do this in the Form Designer, right?

If so, your code is basically OK. What you are missing is a place to run it from. You can't use GOTFOCUS() because that will never fire while you are in the Form Designer.

The answer is to use ASELOBJ(). In brief, you need to write a little program that uses ASELOBJ() to capture a reference to the currently selcted object. Something like this:

Code:
ASELOBJ(laObj, 1)
loContainer = laObj(1)
loContainer.Label1.Caption = loContainer.Title
&& and so on

Then, in the Form Designer, select one of the labels. Then run the program, for example from the command window.

(The above code is only meant to give you the general idea. It could be improved, for example by adding error checking and other features.)

If you need to do this particular job frequently, it would be worth registering the program as a builder, but that's not essential.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Craig S. Boyd once has had a shot at design time changes of compound controls. Here's a sample of a scrollbar which adapts from horizontal to vertical automatically, the technique he uses can also be applied to your case, any design time changes in fact.

I think he never continued and refined on the idea, once he began programming of VFP Studio, but you could refine and perhaps simplify this to your case.

Bye, Olaf.
 
Mike, Olaf,

Thanks for the suggestions. I searched previous posts on registering a builder and found that you had both replied to a similar request back in 2006. thread184-1296475

That gave me some additional insight.

I've not registered a builder before so if you have any tips on that topic -- pass them my way.

It might be easier to copy the labels from one form to the next and manually reset the caption property on the new form.

Thanks -- cd.
 
Just to be clear: You do not need to register the program as a builder in order for it to work. You can run it from the command window, assign it to a function key, or even create a toolbar button for it.

Registering it as a builder makes sense if you want to run the program many times, and especially if it is to be used by other programmers. It allows you simply to right-click on a control and chooes the builder from the context menu. But it does not change the functionality in any way.

In other words, don't get bogged down with the builder if you are only going to be using this technique occasionally.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top