The Friend and New Keywords

[Previous] [Next]

Another thing you should avoid in connection with MTS is the Friend keyword. MTS won't recognize a Friend property, a Friend sub, or a Friend function for what it is. The reason is that the Friend keyword is a Visual Basic keyword and doesn't belong to COM. If you use it inside MTS, the procedure in question will behave as if it were Private. If you want other objects, be they objects of the same class or of other classes, to be able to call a certain procedure, you must make the procedure Public.

You shouldn't consider this a bug because it isn't. It's entirely a question of non-COM functionality in Visual Basic. In a way, the behavior of the Friend keyword resembles that of the New keyword, which is also strictly Visual Basic and not COM. You should avoid the use of New, too, in MTS applications. You can't always avoid it because a small number of special Visual Basic objects, Collection being one of them, can't be created by COM object creation methods. But whenever you can, at least in the context of MTS and COM+, you should use the CreateObject or CreateInstance method. In Programming Distributed Applications with COM and Microsoft Visual Basic 6.0, Ted Pattison wrote well about creating objects for MTS, and we warmly recommend his book to everybody working with MTS.

When we tried to use the Friend keyword and MTS together in Visual Basic 5.0, our application always bombed. MTS would give us a message box saying, "Out of Memory." We haven't seen that in Visual Basic 6.0, but we haven't been able to use Friend successfully with Visual Basic 6.0 and MTS either. So we say to you as we say to ourselves, "Don't use it!"



Designing for scalability with Microsoft Windows DNA
Designing for Scalability with Microsoft Windows DNA (DV-MPS Designing)
ISBN: 0735609683
EAN: 2147483647
Year: 2000
Pages: 133

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