New Objects from Type Libraries


Let’s fast forward. Stories, Inc., has updated its StoryTeller program by pro­-
viding a type library. You download the type library STORIES.TLB from www.stories.com. Then you load it in the Visual Basic References dialog box. You open the Object Browser and find the class you want. Then you declare a variable for it:

Dim story As CStory
Set story = New CStory
story.Declaim 9, “Easy”
§

This time, something very different happens. When your source file is compiled, Visual Basic looks in its type libraries and finds the CStory class. The class is essentially a data table with offsets to the address of each property and method. These offsets are bound to each property access and method call in your program when the program is compiled. All you need to execute those properties and methods is the base address of the CStory object they are part of. When the Set statement is executed at run time, Visual Basic gets all the information it needs to create a CStory object from the type library instead of from the system registry. This speeds things up a little, but the big savings comes from having looked up all the method and property offsets at compile time.