Results 1 to 3 of 3

Thread: late binding

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    late binding

    I don't fully understand the concept of late and early binding. I recently started using option strict and my code fell apart arrgh!

    I fixed all of my errors except four of them and here is a sample of what I have left:

    VB Code:
    1. Private Sub tab_25_btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2.     Handles tab_25_btnClearAll.Click
    3.         'Purpose : Clears the CU tabpage
    4.  
    5.         Try
    6.             Client.ClearTab(sender.parent)
    7.             tab_25_optNo.Checked = True
    8.  
    9.         Catch ex As Exception
    10.             ErrorMessage(ex.Message)
    11.  
    12.         End Try
    13.     End Sub

    the error is "option strict disallows late binding' and it highlights the "sender.parent" section. what can I do to correct this?

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Late-binding means the runtime must examine the generic object and try to coerce into the receiving container.

    Early-Binding refers to explicity informing the compiler of what type of object the sender is, and what type of object the receiver is, so it can compile your app at build-time into the appropriate instructions, saving a whole hell lot of work for the runtime.

    For your code, ask yourself, who is the Sender? Assume for example it was a TabPage.

    VB Code:
    1. 'late-binding, compiler only knows Sender is an object (object has no property .parent)
    2. 'with option strict off, it includes code instructing
    3. 'runtime to call a "parent" method when it runs
    4. Client.ClearTab(sender.parent)
    5.  
    6. 'compiler now has instructions from you to cast the sender
    7. 'into a TabPage....which the compiler knows has a "parent" method
    8. Client.ClearTab(DirectCast(Sender, TabPage).parent)
    Last edited by nemaroller; Jul 14th, 2004 at 09:05 AM.

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    You need to put a CType in there somewhere. I'm not familiar with your paticular construction but the following is an excerpt from code I use

    VB Code:
    1. Dim intcount As Object
    2.         For Each intcount In Controls
    3.  
    4.             If TypeOf intcount Is CheckBox Then
    5.                 CType(intcount, CheckBox).Checked = True
    6.  
    7.  
    8.             End If
    9.         Next
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width