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, propertysmile [:)]

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.

property copyenabled() as boolean


            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...

unfortunately because of the amount of junk mail being generated from the weblog i have switched off comments. please post your comments, if any, at www.foxite.com

Leave a Reply

Your email address will not be published. Required fields are marked *