Using the Interop Forms Toolkit in VFP9 - V
Exposing properties
In previous posts I used the example of creating a toolstrip
as an Activex. I showed how the Click could be exposed and trapped in VFP:
I, II & III
In this post I will show how the various properties can be
exposed so that they can be read or changed from VFP once the Activex is
created.
The toolstrip has many properties of its own as well as
properties for each of the buttons added. These can only be accessed externally
if they have been exposed within the Activex. Since there are literally hundreds
of properties that could be exposed, there is a need to expose only those that
are required for access externally.
Vb.Net has a tool for this. You can insert a snippet of code
by right clicking and then drilling down to select the type of snippet you
want. A faster way is to type the shortcut keyword and then press TAB. You can
find out what the shortcut keys are from the Code Snippet Manager. This is accessed
from the Tools menu of the VB IDE.

Fig 1. Code Snippet Manager view for inserting Property code.
Open the bbToolstrip project you created earlier and open
the code window. We will be exposing the Enabled property for each button so
that we can enable/disable them as needed.
Scroll to the section as shown and type the word
property and then press the TAB key.
A complete snippet will be added automatically for you with the areas to
be changed highlighted. If you didn't notice the shortcut keyword for inserting a Property snippet is well, property![Smile [:)]](/emoticons/emotion-1.gif)
All that is required is to modify the template code above to
reference your properties. Below is the code after changes to expose the Enabled
property of the Copy button which I have changed the name of to CopyToolStripButton and the new property is called CopyEnabled.
This is essential since we need to uniquely identify each object by name
as well as each property since we will be exposing the Enabled property of
different objects.
Public Property CopyEnabled() As Boolean
Get
Return Me.CopyToolStripButton.Enabled
End
Get
Set(ByVal value
As Boolean)
Me.CopyToolStripButton.Enabled =
value
Me.CopyToolStripMenuItem.Enabled =
value
End
Set
End Property
The above code snippet will expose a property called
CopyEnabled with a .T. / .F. value which will affect our Copy button on the
toolstrip.
Do this for each button and for each property of each object
you want to expose. There is no short cut here other than the Snippet code
inserter, so just add code for only those properties you want exposed.
Now
recompile the Activex and we are done with VB for now.
In
VFP, open the form you created earlier or just create a new form and drop the
Toolstrip Activex on it. Open the properties window and see that the properties
we exposed earlier appear there. Note that you can change the property in the
property window and the toolstrip reflects this change.
The property window with the new property
CopyEnabled is .T.. Button is Enabled.
CopyEnabled = .F. Button is Disabled!
This
value can be set also at runtime. In this way you can easily expose properties
of the Activex for access externally in VFP.
Till
next time then...