The Holy Grail of Code Reusability

The great news is that VB6.0 gives us the ability to create new controls that can be bound not only to a few predefined fields, but to an entire record in the database - and we don't need to specify these fields in advance! This means that you can create your own ADO Data Control, just like the one in your tool palette! This is real power. So let's say that we wanted to create a new ActiveX control that we could simply draw on a form that would manage all of our data input requirements. How? It's simple!

Remember the data class we wrote a few chapters back that manages all of the bound fields on a form for us? The class was smart enough to know which fields were bound to the data control. The class locked the fields when they were not in use so the user could not enter any information unless the class was in an Edit mode. Then, when the user pressed Edit or Add, the class unlocked the fields and handled all of the editing for us. This was a great exercise and certainly cut down on our programming time by handling the complexity of managing the user input.

However, we must include the class with each program we write. Or if you want to give the class to an associate, the source code has to be distributed because the class code gets compiled right into the source of the program. There was always the risk that the user of our class might tweak the code for the current project, thus making it non-standard and therefore not reusable.

So if we wanted to distribute the functionality of our class in a compiled form so the programmer couldn't change it, we were out of luck. Or if we wanted to provide the functionality of a generalized data bound control to a C++ or Delphi programmer, we just couldn't do it. Until now.

VB 6.0 allows us to create our own bound controls, just like the controls found on your tool palette. And best of all, they can be compiled into real **.OCX **files so that you can distribute the binary files to programmers that use any language that can use bound controls.

© 1998 by Wrox Press. All rights reserved.