December 15, 2004 22:19:47
The code component is the previous so-called OLE server, which is an object library for encapsulating the object, providing a simple method for code reuse. For example, a created process library can be used for Microsoft Visual Basic, or a desktop application for Visual Basic for Applications, such as Microsoft Office. With Visua Basic Enterprise Edition, code components can be part of the enterprise system, providing data services and business rules in the remote computer. The chapters relatively close to this relationship include "scalability and multi-thread" and "asynchronous callbacks and events".
Global object and code base 1. When references to this part from other projects, the properties and methods of global objects will become part of the global namespace. In the process of creating this GlobalMultiUse class module, the object created by this class is all normal objects. 2. Setting a class Instancing property to GlobalMultiUse or GlobalSingleUse to use the properties and methods of this class as global functions, but the objects created from this class are not global from this class. . 3. Pollution in full namespace is a very serious problem. 4. Each client that uses the GlobalMultiUse class's properties and methods will get one of your own class instances. In other words, the word "Global" in GlobalmultiUse does not mean "all clients share the same global instance". 5. The global object cannot be used instead of the global process in the VB and VBA libraries. These libraries are always displayed at the forefront of the "Reference" dialog leading to other libraries. If the process name in the global object is the same as the library, only the process of accessing the global object only before the process is prior. 6. Only process external components can set the instancing property of the class module to globalsingleuse. If this is done, the memory of each client will be loaded with an independent instance of the part. This will require more memory than using the GlobalMultiUse object.
Scalability and multi-threaded
Visual Basic's unit model thread
7. In Visual Basic, the unit model (Apartment-Model) is used to ensure the security of the thread. Each thread of the cell model thread is as if it is a unit, all objects created on that thread are in this unit, which does not feel objects in other units. 8. In addition to maintaining a stand-alone copy of global data, the Sub Main process is performed in each new unit (ie each new thread). Otherwise, the global data cannot be initialized for each thread. There is a further discussion on this issue in "Designing Thread Safety DLL" and "Design Multithreaded Process". 9. All components created by Visual Basic use a cell model, whether the part is a single thread or multi-threaded. Single-threaded components have only one unit that contains all objects provided by the components. 10. Forms, UserControls, UserDocuments, and ActiveX designers are threads. 11. When changing the thread mode of the existing engineering, if the project uses a single-threaded ActiveX control, an error is generated. Visual Basic is prohibited from using a single-threaded control in the engineering using unit threads, 12. Selecting the User Interface Perform Options will sacrifice all forms requiring user interaction, including message boxes and system error dialogs. The cell model thread in the cell model thread has the limitations of the cell model thread in Visual Basic. The development environment does not support multi-threaded debugging. If there is Microsoft Visual Studio, you can compile the unit threaded components into native code with debugging information, and then use the Visual Studio debugger to debug. If it is a test and debug process, a multi-threaded client application is required. The method that MDI parent forms and subform sharing data is difficult to ensure the thread is secure. Therefore, the MDI form is not allowed in the unit threaded engineering. For unit-threaded ActiveX DLL projects, the ActiveX EXE project selected for each object (or more than one thread number than one), "Add MDIFORM" on the Project "menu will be unavailable. . If the thread mode is changed to "Unit Thread" in the project containing the MDI form, an error will occur. In addition to the poor performance, single-threaded ActiveX control causes many problems in multi-threaded client applications. Therefore, Visual Basic prohibits the use of single-threaded controls in the process of thread mode being set to "unit thread". For more information, see "Converting existing projects into unit mode threaded projects". Friends attributes and methods can only be called by objects on the same thread. Because they are not part of an object public interface, they cannot be scheduled between threads. The ActiveX document in the ActiveX EXE project is not a thread secure, unless "Each object corresponds to a thread" or a "thread buffer pool" option of the buffer number. If the thread displays a form with a VBModal property, the form will only modalize the code and form on the thread. The code running in other threads will not be blocked, and the form displayed by other threads will also remain active. The drag and drop operation between the forms and controls is only valid when the drag and drop sources and drag and drop targets are in the same thread. However, the drag and drop of OLE is universal.) The DDE between the form is only valid when the form is in the same thread.