Name Collisions

Name Collisions

Name collisions happen when the Ax wrapper class includes a property, method, or event that has the same name as the ActiveX control. Take, for example, an ActiveX control that has a property called Size. The ActiveX control s Size property will be in conflict with the Size property that the Ax wrapper adds to the control. To manage this type of conflict, the Ax wrapper will rename the ActiveX control property to CtlSize. If you need to set the ActiveX control s size property, you should set CtlSize. To set the size property managed by Windows Forms on behalf of the ActiveX control, you would set the Size property. Fortunately, name conflicts will not occur for most ActiveX controls. When the Upgrade Wizard detects a name conflict, it will upgrade your code to use the correct property or method even if the property or method has been renamed.

Naming conflicts are not new to Visual Basic .NET. Visual Basic 6 also manages name conflicts for you. As we mentioned earlier in this chapter, Visual Basic 6 creates a wrapper class for ActiveX controls. If there is a conflict with a property or method name, the wrapper hides the ActiveX control property or method in favor of the wrapper s property or method. To access the underlying ActiveX property, you need to use the ActiveX control s Object property. For example, the following Visual Basic 6 code:

MyFavoriteControl.Object.Tag = "My control's internal tag" MyFavoriteControl.Tag = "The Tag property given to me by Visual Basic"

upgrades to the following Visual Basic .NET code:

MyFavoriteControl.CtlTag = "My control's internal tag" MyFavoriteControl.Tag = "The Tag property given to me by Visual Basic"

Event Name Collisions

If an event name conflicts with another property or base class event name, the Upgrade Wizard renames the event. It does so by appending the word Event to the end of the event name. One ActiveX control that exhibits this behavior is the Microsoft WinSock control. If you place a WinSock control on a Windows form and view its events, you will see that the Close and Connect events have been renamed CloseEvent and ConnectEvent, respectively. Since most controls contain unique event names, you will seldom encounter this issue. Even if you do, you probably will not notice. If a name conflict does occur, the renamed event is easy to find, since the event name is mostly preserved. The Upgrade Wizard automatically upgrades your code to use the renamed event name, so you should not encounter any issues after upgrading your Visual Basic 6 application.



Upgrading Microsoft Visual Basic 6.0to Microsoft Visual Basic  .NET
Upgrading Microsoft Visual Basic 6.0 to Microsoft Visual Basic .NET w/accompanying CD-ROM
ISBN: 073561587X
EAN: 2147483647
Year: 2001
Pages: 179

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net