Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Nov 18, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 TextBox

Public Property Set Client(NewObj As Object)
   ' Set new TextBox as Client property.
   If TypeName(NewObj) = "TextBox" Then
      Set m_txt = NewObj
      ' Raise error #13 --> Type Mismatch
      Err.Raise Number:=13, _
         Source:="CMyClass.Client", _
         Description:="Client property must be of type TextBox."
   End If
End Property

Public Property Get Client() As Object
   ' Return TextBox as Client property.
   Set Client = m_txt
End 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.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date