Results 1 to 4 of 4

Thread: Early binding Late binding

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Location
    India
    Posts
    91

    Early binding Late binding

    Hello,
    Can any one tell me what is early binding and late binding in context of objects.

    what is difference between
    dim obj as new data

    and

    set obj=new data

    where and when we use these.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Early binding - You have a reference to a library included in your project, and you use the objects in the library like this...
    VB Code:
    1. Dim obj As [b]MyObject[/b]
    2.  
    3.     Set obj = [b]New MyObject[/b]

    Late binding - You may or may not have a reference in your project, and you use objects like this...
    VB Code:
    1. Dim obj As [b]Object[/b]
    2.  
    3.     Set obj = [b]CreateObject("MyLib.MyObject")[/b]

    The second relies on the latest version of the interface to the object as dictated by the registry, rather than the reference in the project.

    As for your second question, when you instantiate an object inline, the Class_Initialize sub isn't really called until the object is first referenced. When you say Set obj = New MyObject, the Class_Initialize sub is called right then.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Early Binding:

    VB Code:
    1. Public Sub EarlyBoundArgument(objWorkbook as Excel.WorkBook)
    2. objWorkbook.ActiveSheet.Select
    3. End Sub

    Late Binding:

    VB Code:
    1. Public Sub LateBoundArgument(objWorkbook as Object)
    2. objWorkbook.ActiveSheet.Select
    3. End Sub

    The major diference is the VB IDE can catch errors before you compile in the case of Early Binding.

    With Late Binding, the code might not even work and the compiler will still give you a valid executable that may crash at runtime.

    SO basically Late binging happens at run-time and early binding happens at compile time.

  4. #4
    Addicted Member
    Join Date
    Jun 2002
    Location
    Brugge, Belgium
    Posts
    208
    crptcblade is correct about the registry. Late binding enables you to create a program that eg works for Microsoft Word. You would then define an object and create the object 'later' based on a Word document.

    With early binding you would set your Word 'dlls' into the references of the project and bind that way.

    This causes problems if you have to distribute your exe on machines that have different Word versions.

    I had this problem with a client. And as a developer you can't always tell your clients to upgrade to your latest version of Word or any other program you're using.

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