VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 12

Sending Messages to the User from a COM Component

Depending on its function, your COM component might or might not have any user interface. If it does require user interface, that interface will have to be based on one or more forms included in the server component project. You must be aware of the way each form affects the lifetime of the server component application. When the server component is an in-process server component, you must also be aware of the effect your form has on the client application.

It is important to keep in mind that the forms and other elements of the user interface, such as message boxes, belong to your COM component, and not to the client application. Although this is an obvious fact, its consequences might not be so obvious. When an out-of-process server component displays its interface, for example, that interface might not be on top of other windows that the client is displaying.

a name="managing-forms-in-an-out-of-process-server-component">Managing Forms in an Out-Of-Process Server Component

In an out-of-process server component, a form may be the startup form for the server component application's project. You must unload this form and any other forms before the server component can be unloaded.

Because of this, you shouldn't use formname.Hide in your out-of-process server component's code when it is completely done with a form. Instead, the out-of-process server component application should load the form when it needs it, and unload it whenever it does not need to be visible. If you have copies of the form in memory, an out-of-process server component will continue to run even after it is not needed.

Managing Forms in an In-Process Server Component

A form is never the entry point into an in-process server component, because the server component runs in the same process space as the client, and the client itself initiates and terminates the server component.

Although you can generally display modal forms as needed in an inprocess server component, modeless forms present more problems. The only client applications that will support modeless forms in an in-process server component as of this writing are as follows:

  • Clients that are written in VB5 or VB6.

  • Clients that use Visual Basic for Applications 5.0 or later. This includes the Microsoft Office 97 suite and later versions, as well as any third-party applications that carry the Visual Basic Technology logo.

  • Internet Explorer 4.0 and above.

When you program a server component, you can't foresee which clients will attempt to use it, so you can't tell whether your server component's client supports modeless server component forms. If you want to be very cautious, you can just avoid ever displaying a modeless form in an in-process server component.

For more flexibility, however, you can verify the App object's NonModalAllowed property in the server component's code. If the property is True, the current client supports modeless forms in the server component. You might write code similar to Listing 12.26 so that your server component could display a form either modelessly or modally, depending on what the client allows.


If App.NonModalAllowed Then
   frmMsg.Show vbModeLess
   frmMsg.Show vbModal
End If

Even if an in-process server component still has forms loaded, it may be able to unload anyway, providing all forms are invisible and certain other conditions are fulfilled.

Note that an out-of-process server component can't terminate with any forms loaded, even though they are invisible.

NOTE - App.NonModalAllowed Gives Incorrect Results in the VB Debugging Environment : Typically, you can test your component against another application by running your app from the VB environment and specifying the test client from the Debug dialog box. The VB environment will always return App.NonModalAllowed as True, however, regardless of whether the external application really does support nonmodal forms in a component. The only way to really find out whether a potential client supports nonmodal forms is to compile your application and test the client against the compiled version—or against a small compiled test application that checks the value of App.NonModalAllowed.


<< Previous | Contents | Next >>


Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved