Presentation is loading. Please wait.

Presentation is loading. Please wait.

‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.

Similar presentations


Presentation on theme: "‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7."— Presentation transcript:

1 ‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7

2 ‘Tirgul’ # 7 Objectives Brief on COM COM and Classes ActiveX DllCreating Objects – ActiveX Dll Registering an Object Version Compatibility issues

3 ‘Tirgul’ # 7 Abstract In the world of the enterprise, employers want that something more then just Forms and Controls That something is called COM –It's a way of organizing your code so it can be used over and over again. –It's a method of helping create a bug-free development environment. –Just after making your life a little harder, makes it lot easier.

4 ‘Tirgul’ # 7 What is COM? you're already a COM programmer! –Every time you set the Text property of a Text Box, you're using COM. COM is a method of communication

5 ‘Tirgul’ # 7 COM is a method of communication Imagine a television remote control –You press button one and the television tunes into Channel 1, 2… –You press the power button and the television turns itself off. You just press the button and it jumps into action.

6 ‘Tirgul’ # 7 COM is a method of communication That’s applies to the world of programming. You don't really know what happens when you change the Text property of your Text Box. Under the covers, it's probably making two-dozen API calls – but to the end user, it just displays a certain piece of text in the box.

7 ‘Tirgul’ # 7 COM is a way of reusing code You can use Com Object again and again anywhere. –A COM widget could be accessed from any program at any time. (Visual Basic, Excel C++ Program) So COM is all about creating 'widgets' that can be reused.

8 ‘Tirgul’ # 7 COM is based around real-life objects After COM have been made, it’s easy to use. Add a customer –Instead of adding lots of data access code, validation algorithms, and weighty database DLLs to your application – wouldn't it be easier to run something likeCustomer.Add

9 ‘Tirgul’ # 7 Classes -> COM All of our work will be surrounding the creation of a class – which could later be turned into a real life COM object

10 ‘Tirgul’ # 7 Classes check list Variables Properties (Let/Get) (hopefully).. Subs, Functions, Parameters Collection What else? –Enumeration –Events – Not in the scope

11 ‘Tirgul’ # 7 create a real-life COM object ActiveX DLL – A.DLL program that contains classes. ActiveX EXE – A.EXE program that contains classes. ActiveX Control – A project that allows you to create controls in your toolbox. ActiveX Document EXE – A program that runs on a Web page, in.EXE format. ActiveX Document DLL – As above, but.DLL format.

12 ‘Tirgul’ # 7 My first object! We have discussed objects as controls in VB (Textbox, ComboBox) - you should be remembering these by now!) When you make a control, it has a user interface (that means you can visually see something on the screen, such as the textbox itself Another kind of object is one that doesn't have a user interface, and we call this a DLL (or Dynamic Link Library if you want to impress your friends).

13 ‘Tirgul’ # 7 ActiveX Dll Click File, New Project and select ActiveX DLL: make sure that the Instancing property is set to 5 – MultiUse, Allows us to compile the DLL and expose the class module to other programs (such as the object browser.

14 ‘Tirgul’ # 7 Build the DLL Save the project, and a click File, Make Project1.DLL. You've just complied your first Dll object!

15 ‘Tirgul’ # 7 Testing.. Add another project - File, Add Project, Standard EXE. Because a DLL is not a control, we need to make a reference to it (because we are not loading any kind of user interface)

16 ‘Tirgul’ # 7 Testing.. Click File, References and scroll down and select Project1:

17 ‘Tirgul’ # 7 Browsing the Object press F2 to load up the object browser and select Projec1 from the combo box. Check the Methods..

18 ‘Tirgul’ # 7 Explanation An ActiveX DLL's code is executed within the main program's address space. It behaves as if the class was created within the main program's code. Because the code lies inside the program's address space, calling methods is very fast.

19 ‘Tirgul’ # 7 Registering a component when you come to distribute your DLL to another machine and it doesn't work.. Each DLL (or component) on your machine has to be registered (including controls). Once registered, an entry in to the registry is made.

20 ‘Tirgul’ # 7 Using Regsvr32 Tool Microsoft tool for registring DLL ’ s and OCX ’ s Simply Drag the Object into the TextBox

21 ‘Tirgul’ # 7 Main sub In the module you can add a main sub: Sub main ‘Add code that will run when the ‘component is created End Sub

22 ‘Tirgul’ # 7 Compatibility Problem: –compile the ActiveX DLL, –then compiled a test program that used our DLL. –Then we recompiled our DLL – something you usually do after you make changes. Suddenly, our test program no longer worked!

23 ‘Tirgul’ # 7 Compatibility Open up your project Click 'Project Properties' Click the 'Component' tab

24 ‘Tirgul’ # 7 Version Compatibility No Compatibility – When compiled, your COM component gets assigned a new 'signature'. Programs looking for older 'signatures' (the previous version of the DLL) – simply flop Project Compatibility – When compiled, your COM component is assigned a new signature – and still, any using-applications still flop. The only change here is that 'big' differences between your current project and a previous DLL project are highlighted as you compile. Binary Compatibility – When compiled, your application attempts to keep the signature of a previously compiled DLL, thus ensuring any applications using it don't magically turn into the Blue Screen of Death. However if the differences between your previously compiled DLL and your to-be-compiled DLL are too great, a new signature must be assigned

25 ‘Tirgul’ # 7 ActiveX DLL Creation Summary 1.Determine the features your component will provide. 2.Determine what objects are required to divide the functionality of the component in a logical fashion When you create a new ActiveX DLL, the steps you ’ ll generally follow are these:

26 ‘Tirgul’ # 7 ActiveX DLL Creation Summary 3.Design any forms your component will display. 4.Design the interface — that is, the properties, methods, and events — for each class provided by your component. 5.Create a project group consisting of your component project and a test project.

27 ‘Tirgul’ # 7 ActiveX DLL Creation Summary 6.Implement the forms required by your component 7.Implement the interface of each class. 8.As you add each interface element or feature, add features to your test project to exercise the new functionality. 9.Compile your DLL and test it with all potential target applications.


Download ppt "‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7."

Similar presentations


Ads by Google