Visual Basic 2005 New Function Reviews (Sevente) - My.Forms and My.webservices for My Namespace

xiaoxiao2021-03-06  170

If my.application, my.computer and my.user are collectible libraries that are commonly used by VB2005, My.Resources is a strong type package for project resources, then My.Forms and My.WebServices are a form and A excellent example of the web service usage mode. Programmers upgraded from VB6 to Visual Basic .NET often not adapt to VB.NET's new form programming mode. Because VB.NET's form is class, you must create an instance to use, and VB6's form is both a class and an object without creating an instance. In VB.NET, you often use such syntax to use the form:

Dimform2 as new form1 () frMform2.show

However, in such a syntax display form, communication or data transfer between individual forms is very difficult. For example, the newly generated frMform2 is difficult to do if you want to access another form FORM1 because frMform2 cannot obtain reference to the Form1 instance. Many beginners can't get clear, strength and references, therefore often encounter suffering. Even if you are familiar with these concepts, sometimes you can't use the correct way to solve the problem of the form of each other. Many solutions, such as passing data by constructing data, through global variables or static variables, or even instances of all forms in the module, etc., they will increase the coupling between the form, or waste RAM. In order to completely solve the problem of formal creation and interview, Visual Basic 2005 introduced My.Forms. Although My.Forms is in my namespace, but use it does not need to enter My.Forms. Suppose you have two forms - form1 and form2, Form1 is a startup form, now you want to display FORM2, the new syntax is like this:

FORM2.SHOW

This use is almost the same as VB6. FORM2 is the class of the form, how can I use it directly? Because My.Forms maintains a default instance for each form in the project, the method is very similar to the Singleton mode - each form has a default instance, and there is a global access point, just through the form of the form. Access to it. This approach solves the problem of forms access to each other because each form can access the default instance of any other form at any time. For example, you want to modify the text of a TextBox in Form1 in Form2, just like this:

Form1.textBox1.text = "Hello"

The constructor or static / global variable is not required for any transmission parameters. Most forms in a project require only one instance, so this mode is suitable for any item. Whether it is a novice or older, I recommend using My.Forms's functionality, he is the best mode to solve the form of the form, and will not waste memory because it only has the first visit to the desired form. Build it.

The principle of My.WebServices is exactly the same as My.Forms, because the original WebService agent class needs to create an object to be used. WebService should have a consistent access point for the project globally, so VB2005 will replace the instance of the proxy class, and maintain it in My.WebServices, you can visit him at any time. For example, your project adds a web reference to Service1 service, it provides a method called Method1, the previous Visual Basic you must write:

Dim myservice1 as new service1 () DIM MyResult as integer = myservice1.method1 ()

And now, no matter where, you can write directly:

MyResult = my.webservices.service1.method1 () without having to manually create an object of the agent class.

Today, I have introduced six major functional areas in my namespace, there is a My.Settings left because it is defective in the current beta version, so I will find a chance to introduce it. Next time, I will introduce how to use my namespace in C # and other languages, and how to extend the functionality of MY namespace.

转载请注明原文地址:https://www.9cbs.com/read-128292.html

New Post(0)