I have a solution, guys!! (first of a series)
hey, agent, I'm sorry but I didn't understand how you handle events like Click and DblClick etc. Just to be certain I was understood correctly - I load not only the UserControls at runtime. I actually load a number of Instances of ctlAnything - which In turn finds his matching XML (say - ctlAddress.xml) and XSL, and load constituet controls based on it.
Now the sollution (It's not going to be complete since it's confidential Information of Amdocs (Israel) Ltd.):
Ok, you make a UserControl to run with my program, right? So you build an XSL to describe his components, and an XML to describe which component is used (you could use other structure, that's what I did).
Now, the XSL of a control contains templates such as this:
Code:
</template match="txtName">
<CONTROL>
<NAME>txtName</NAME>
<TYPE>vb.TextBox</TYPE>
.
.
.
<ADDINFO> (that's where I put control information that is not bound to a property
</ADDINFO>
</template>
Now, suppose we want to handle the Click event on the 'txtName' textbox? we need the main program to declare a variable WithEvents, but we can only declare a limited number in des-time, and we want infinite at run-time. What do we do?
There is a way. I will continue on my next post, and meanwhile try to find the solution. You can ask me questions about this.
Happy new year, you Cristians out there!
Yhe full solution as posted in Amdocs' discussion forums.
OK. There it is.
My Controls are described in an XML of two levels. The first level describes the User Controls (UC's if you dont mind), and the second describes the Constituent Controls (CCs) of each UC.
excerpt from the first level XSL file used to form the data(the XML file specifies which controls of those listed in the XSL will be created):
<xsl:template match="ctlCustTypeNB">
<CONTROL>
<xsl:attribute name="parent">
<xsl:value-of select="@parent" />
</xsl:attribute>
<CONTROLNAME><xsl:value-of /></CONTROLNAME>
<CONTROLTOP>20</CONTROLTOP>
<CONTROLLEFT>20</CONTROLLEFT>
<CONTROLBACKCOLOR>H8000000F</CONTROLBACKCOLOR>
<CONTROLTABINDEX>0</CONTROLTABINDEX>
<POSITION>1</POSITION>
<CONTROLTYPE>ctlCustType</CONTROLTYPE>
</CONTROL>
</xsl:template>
<xsl:template match="ctlNameGroupBusiNB">
<CONTROL>
<xsl:attribute name="parent">
<xsl:value-of select="@parent" />
</xsl:attribute>
<CONTROLNAME><xsl:value-of /></CONTROLNAME>
<CONTROLTOP>1000</CONTROLTOP>
<CONTROLLEFT>20</CONTROLLEFT>
<CONTROLBACKCOLOR>H8000000F</CONTROLBACKCOLOR>
<CONTROLTABINDEX>0</CONTROLTABINDEX>
<POSITION>1</POSITION>
<CONTROLTYPE>ctlNameGroupBusi</CONTROLTYPE>
</CONTROL>
</xsl:template>
the attribute 'parent' is used to distinguish between forms. It's a different story. For information about XML and XSL transformations, see Web Workshop under MSDN.
Notice the XML Tag <CONTROLTYPE>. My program lookas for a second level XML-XSL pair by the name under this tag.
Excerpt from ctlCustType.xsl:
<xsl:template match="cmbCustType">
<CONTROL>
<CONTROLNAME>cmb<xsl:value-of /></CONTROLNAME>
<CONTROLTOP>200</CONTROLTOP>
<CONTROLLEFT>1800</CONTROLLEFT>
<CONTROLHEIGHT>315</CONTROLHEIGHT>
<CONTROLWIDTH>3075</CONTROLWIDTH>
<CONTROLBACKCOLOR>H80000005</CONTROLBACKCOLOR>
<CONTROLTABINDEX>0</CONTROLTABINDEX>
<POSITION>1</POSITION>
<CONTROLTYPE>VB.ComboBox</CONTROLTYPE>
<CONTROLTEXT />
<ADDINFO>
<DLL>amdocsGeneral</DLL>
<OBJ>CustTypeEvents</OBJ>
</ADDINFO>
</CONTROL>
<CONTROL>
<CONTROLNAME>lbl<xsl:value-of /></CONTROLNAME>
<CONTROLTOP>200</CONTROLTOP>
<CONTROLLEFT>40</CONTROLLEFT>
<CONTROLHEIGHT>315</CONTROLHEIGHT>
<CONTROLWIDTH>3075</CONTROLWIDTH>
<CONTROLBACKCOLOR>H8000000F</CONTROLBACKCOLOR>
<CONTROLTABINDEX>0</CONTROLTABINDEX>
<POSITION>1</POSITION>
<CONTROLTYPE>VB.Label</CONTROLTYPE>
<CONTROLTEXT>Customer Type: </CONTROLTEXT>
</CONTROL>
</xsl:template>
notice ADDINFO on the combobox.
How does my program load this controls?
I have one UC object, called ctlAnything. the program reads the first-level XML, and instantiates a new ctlAnything for each UC lited in the main XML.
ctlAnything, in turn, reads the second-level XML and instantiates its own CCs accordingly.
Now, crasy things happen when ctlAnything encounters <ADDINFO>.
I promise a second part later. Right now duty calls. Send your answer her or to [email protected]
Bye.
Part two.
---------
now, when ctlAnything encounters the ADDINFO tag it searches for two tags: the DLL tag and the OBJ tag.
So, you can see that the event-handling functions are external to the program, you distribute a separate .dll with each
control or group of controls you release, just like you make a separate XML and XSL.
The DLL contains objects that look something like that:
Dim WithEvents myCombo As VB.ComboBox
Private Sub myCombo_Click()
msgbox myCombo.Text 'Or any functionality you want for a CC
End Sub
Public Sub listenTo(ctl As Object)
Set myCombobox = ctl
End Sub
This is an object for a comboBox CC that prints out the text selected when clicked.
Back to ctlAnything - If it finds the DLL and OBJ tags, it uses that data to create an object of that type, add it to a collection and
make it listen to the events of a certain control:
Handlers(i).listenTo(Controls(i)) for example.
I think this is pretty much it. If it isn't, please respond. I'm sorry it's not very specific, I'm terribly busy right now.