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

Adding a new property

Status
Not open for further replies.

edwardtisdale

Programmer
May 30, 2000
18
0
0
US
I looked it up in help and found:

(start paste)
Adding Properties to Controls


You implement properties of your ActiveX control by adding property procedures to the code module of the UserControl that forms the basis of your control class.

By default, the only properties your control will have are the extender properties provided by the container. You must decide what additional properties your control needs, and add code to save and retrieve the settings of those properties.

Properties for controls differ in two main ways from properties of other objects you create with Visual Basic.

Property values are displayed in the Properties window and Properties Pages dialog box at design time.


Property values are saved to and retrieved from the container's source file, so that they persist from one programming session to the next.
As a result of these differences, implementing properties for controls has more requirements and options than for other kinds of objects.

Implement Control Properties Using Property Procedures
The most important consequence of the differences listed above is that control properties should always be implemented using property procedures instead of public data members. Otherwise, your control will not work correctly in Visual Basic.

Property procedures are required because you must notify Visual Basic whenever a property value changes. You do this by invoking the PropertyChanged method of the UserControl object at the end of every successful Property Let or Property Set, as shown in the following code fragment.

Private mblnMasked As Boolean

Public Property Get Masked() As Boolean
Masked = mblnMasked
End Property

Public Property Let Masked(ByVal NewValue As Boolean)
mblnMasked = NewValue
PropertyChanged
 
and so I changedPrivate mblnMasked As Boolean

Public Property Get Masked() As Boolean
Masked = mblnMasked
End Property

Public Property Let Masked(ByVal NewValue As Boolean)
mblnMasked = NewValue
PropertyChanged

to

Private mblnInstancing As String

Public Property Get Instancing() As String
Instancing = mblnInstancing
End Property

Public Property Let Instancing(ByVal NewValue As String)
mblnInstancing = NewValue
PropertyChanged "Instancing"
End Property

in attempt to start to make the right code to put an Instancing property of options Private and MultiUse.

 
And thenProcedure IDs for Standard Properties
Every property or method in your type library has an identification number, called a procedure ID or DISPID. The property or method can be accessed either by name (late binding) or by DISPID (early binding).

Some properties and methods are important enough to have special DISPIDs, defined by the ActiveX specification. These standard procedure IDs are used by some programs and system functions to access standard properties of your control.

For example, there's a procedure ID for the method that displays an About Box for a control. Rather than rummaging through your type library for a method named AboutBox, Visual Basic calls this procedure ID. Your method can have any name at all, as long as it has the right procedure ID.

To assign a standard procedure ID to a property

On the Tools menu, click Procedure Attributes to open the Procedure Attributes dialog box.


In the Name box, select the property.


Click Advanced to expand the Procedure Attributes dialog box.


In the Procedure ID box, select the procedure ID you want to assign to the property. If the procedure ID you need is not in the list, enter the number in the Procedure ID box.
Important Selecting (None) in the procedure ID box does not mean that the property or method will not have a procedure ID. It only means that you have not selected a particular procedure ID. Visual Basic assigns procedure IDs automatically to members marked (None).

...so I did that.

What have I done right? What have I done wrong?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top