Wrapper Class

Wrapper Class

In VB4, how do I create a wrapper class for a textbox?I want to be able to add properties to a textbox.

There are many approaches you can take to this. Typically, you’ll want to expose a Client property of the class, to which you’ll assign the textbox. It may look something like this: 

Private m_txt As TextBoxPublic Property Set Client(NewObj As Object)   ‘   ‘ Set new TextBox as Client property.   ‘   If TypeName(NewObj) = “TextBox” Then      Set m_txt = NewObj   Else      ‘ Raise error #13 –> Type Mismatch      Err.Raise Number:=13, _         Source:=”CMyClass.Client”, _         Description:=”Client property must be of type TextBox.”   End IfEnd PropertyPublic Property Get Client() As Object   ‘   ‘ Return TextBox as Client property.   ‘   Set Client = m_txtEnd Property
 You’ll then have a reference to the textbox and can do with it what you will. See my columns in the January and March 1996 issues of VBPJ for examples of doing this with Listbox and Picture box controls.

 Users of VB5 will want to take a look at the possibilities opened up by declaring the class reference to the textbox using WithEvents! Using this new feature allows your class to recieve all events the the host form normally does, thus greatly reducing the amount of code required in VB4 to notify the class of control events.


Share the Post: