Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multicasting inheritance
Message
Information générale
Forum:
Visual Basic
Catégorie:
Autre
Titre:
Multicasting inheritance
Divers
Thread ID:
00417460
Message ID:
00417460
Vues:
48
Hi Vin. After our discussion over the past couple of days I got inspired to take advantage of Multicasting. I am pretty efficient in creating re-usable code but I wanted to see if I could take it a notch further with multicasting. I have a form with a couple dozen or so text boxes. Each text box has a Change and Validate that fire off some generic validation routines in the business object. They look like this:
Private Sub txtAddress1_Change()
    If Not mflgLoading Then oBusObject.TextChange ActiveControl
End Sub

Private Sub txtAddress1_Validate(Cancel As Boolean)
    ActiveControl.Text = oBusObject.TextValid(ActiveControl, Cancel)
End Sub
I deleted all the Change and Validate code and replace them with a GotFocus on each text box. It looks like this:
Private Sub txtAddress1_GotFocus()
    Set oBusObject.TextBox = ActiveControl
    Set oBusObject.ActiveControl = ActiveControl
End Sub
And added the following to oBusObject:
Public WithEvents TextBox As TextBox
Public ActiveControl As TextBox

Private Sub TextBox_Change()
   ' Process Change business rules based on properties of ActiveControl
End Sub

Private Sub TextBox_Validate(Cancel As Boolean)
   ' Process Validate business rules based on properties of ActiveControl
End Sub
It's still more code than true inheritance but it works! An unlike my previous method I only need to populate one method (event) for each control.

Can you see any way to make this even tighter?
George
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform