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!

Add a property to a custom class in class designer

Status
Not open for further replies.

Doug Lindauer

Programmer
Feb 2, 2017
36
US
Ok, I'm stuck on this one. Is there some way to a add a property to a class at design time so that it appears in the properties list and is available to other objects in the class at design time?

This is my first attempt to make my own class. It occurred to me that it would be handy to incorporate a label with a grid and that the label would know what table was in the grid and could do things to the table if you double clicked it. So I've started with a container object and stuck a grid and a label in it. I want to add code to the double click event of the Label object but that procedure doesn't seem to have any way to refer to the properties of the grid.

If I can get this working, I want to add a list control which shows the available indexes for the table to allow a user to choose an index. But first things first I suppose.
 
You have your container, a grid on it (called grid1) and a label (label1). Within the DblClick of the label, you can refer to the grid with THIS.PARENT.GRID1. Intellisense will then show all the grid properties.

Bye, Olaf.
 
Olaf has answered your second question (how to reference one object from another).

To answer your first question (how to add a property to a class at design time): open the class in the Class Designer. Then select New Property from the Class menu. In the resulting dialogue, enter a name for your custom property and an optional description (you can leave the other boxes at their defaults). Then press Add, then Close.

That last step is important. If you close the dialogue without first clicking the Add button, nothing will happen.

You can now reference the property, either in code in the Class Designer, just like any other property.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I only addressed the grid referencing, as you use the already existing dblclick event and want to access already existing grid properties like the recordsource. You don't need something new as far as I can see.

When we're at adding new properties (and in the same manner also user-defined methods): One important thing to notice is, you can only add properties on the level of the class, in this case to the outer container. If you want to add properties to the grid or the label, well, you have to define a class based on the base grid to add a property on that level, define your own label class based on the base label and then in the third step define a class based on container containing objects based on your grid and label classes.

It's still exactly similar to the form designer you already know, you also can only add properties and methods at the level of the form, not to each object placed on it.

Bye, Olaf.
 
much thanks both to Mike and Olaf. I did blunder around and thought about it a lot and actually found the 'parent' reference thing just before Olaf posted his reply but it was still good to see that I'd found the right thing. So both replies were just what I needed. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top