I've created a user control. I would like a copy of the control on a sub
form to display a carbon copy of the data on the main form's control. Is
there a slick way of doing this by just setting the sub form control = to
main form control? If I create a user control object or a "myUserControl"
object, neither like the "set ucCopy = frmMain.ucSource" statement. I'm
only seeing the "grunt" version of doing this.
06-08-2001, 10:42 AM
Re: User Controls
Yours is a very genuine problem and a good problem I must say. And let me
tell you beforehand, I dont have an easy solution to it.
a.f.a. I am able to understand, you are talking about "Cloning" a concept
provided by Java Classes, because they exposed all "Meta" Data automatically.
Whereas, in COM paradigm (at least VB classes) the objects dont expose the
MetaData automatically (by MetaData, I mean that a class is exposing what
all properties it has and of what type and value).
What you want is all the properties of one controls to be automatically set
to those of another (given the fact that they are of same type). You problem
could be solved, if we could somehow get the reference of "Persistible" Interface
of one object and set it to that of another and that's it!
Many options arise to do that. Lets analyse them one-by-one:
1) Since all ActiveX components are persistable (they use PropertyBag for
storing their property values in .frm/.frx files) they should have been "persistable".
But I found they are not. At least their Typelibrary says so. When you see
the typelibrary of an ocx control, it is not exposing any "Persisting" interface
(at least publicly). So its 'impossible' to get a reference to Persistible
interface, so this option is ruled out!
2) Then we think of "Persistible" classes (as MS calls them). They too use
a similar PropertyBag and have WriteProperty etc methods. But (unfortunately)
they too dont expose any public interface for this. So this option is also
3) Third and the most dirty option that comes to my mind is of manually-reading-the-typelib-and-setting-all-properties.
This is a tedious one, but possible.
3.1) TlibInfo32 has a method called ClassInfoFromObject (at runtime,
you can get the reference to the class info of an "Object" and read all its
property-names and types.
3.2) Loop through all these properties of 'first' object.
3.3) Get their values one by one using CallByName(...) and set them to
corresponding properties of 'second' object.
The solution above is for a generic routine that can "Clone" any one object
to another (of tha same type of course).
If you want to cut this short to a 'specific' routine cloning just one object-type,
set all the properties manually:
Hope you got an idea of doing tis stuff, that MS should have done by now
(I amnot aware of .NET, but I dont see any such thing till VB6!)
"Jeff Trate" <firstname.lastname@example.org> wrote:
>I've created a user control. I would like a copy of the control on a sub
>form to display a carbon copy of the data on the main form's control. Is
>there a slick way of doing this by just setting the sub form control = to
>main form control? If I create a user control object or a "myUserControl"
>object, neither like the "set ucCopy = frmMain.ucSource" statement. I'm
>only seeing the "grunt" version of doing this.