Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing a control as a reference
Message
De
30/12/2004 21:37:30
Chris Bohling
Myers and Stauffer LC
Shawnee, Kansas, États-Unis
 
 
À
30/12/2004 20:25:23
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00973454
Message ID:
00973467
Vues:
14
>As I have two logs on the form, I would like to pass an additional parameter for the TextControl to be used. So, I have updated the function like this:
>    Private Sub AddToLog(ByVal tcString As String, Optional ByVal toObject As Object = "Log")
>        toObject.Text = toObject.Text + "Started: " + Date.Now + Chr(13) + Chr(10)
>        toObject.Text = toObject.Text + tcString + Chr(13) + Chr(10)
>        CursorLog()
>    End Sub
>However, this generates development time error. This is normal as toObject is not a control on the form. How can I achieve that?

This code, which uses Reflection, works:
Public Class Tests
   Public Sub PassControlRef(ByVal controlRef As Object)
      Dim TextProp As System.Reflection.PropertyInfo
      TextProp = controlRef.GetType.GetProperty("Text")
      If Not TextProp Is Nothing Then
         TextProp.SetValue( _
         controlRef, _
         "Message: Passing this control as an object reference worked.", _
         Nothing)
      End If
   End Sub
End Class
Christopher Bohling, Consultant
http://www.ChristopherBohling.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform