N-tiers development mode (ASP/ASP. NET, VB6/VB. NET calls use COM + components)

Source: Internet
Author: User

Continued: N-tiers development method (Registration and modification of COM + components)

After the component is installed, the next step is to call and use the components we have written. Let's assume that the name of the component we wrote is as follows:

Package: kdmo1000
Project: pdmomenu
Class:
Cdmomenu1 (no transaction)
Cdmomenu2 (with Transaction)
Assume that one function in cdmomenu1 is getnodename, And the nodeid (integer) parameter is input, and the nodename (string) is returned)
Getnodename (byval nodeid as integer) as string

Late binding:

The call method I mentioned here is the call method using late binding. That is to say, the component will not be registered to your asp.. Net project, or your VB. net project, when the system is running, it dynamically uses the object bind from the server. The disadvantage is that you cannot use obj. To select the attribute method in the component, you must use your own keyin when using the attribute method. However, when your components have been changed, you do not have to re-reference your components in one project. In addition, whether you write ASP or ASP. net, VB, and VB.. net, you call components in the same way.

Call components:

Call components are as follows:

ASP:

SetOBJ = Createobject ("Pdmomenu. cdmomenu1") Nodeid = 2 nodename = obj. getnodename (nodeid)

 

VB:

Dim OBJAsObject set OBJ = Createobject ("Pdmomenu. cdmomenu1") Dim nodeidAsInteger nodeid = 2 dim nodenameAsString nodename = obj. getnodename (nodeid)

ASP. NET/VB. NET

 
DimNodeidAs Integer= 2 using OBJAs Object= Createobject ("Pdmomenu. cdmomenu1")TryDimNodenameAs String= Obj. getnodename (nodeid)CatchExAsExceptionMe. Lblerrmsg. Text = ex. Message. tostring ()End TryEndUsing

. Net call components must be released by themselves:

From the aboveProgramCodeYou can find that the call component process is almost the same. When using. Net to write, the call method can be simpler.

after the component is called for execution, you can find the component in the package in [Component Service] and turn it up. If ASP and VB6 are used to call components, it can be found that after the component call is complete, the component rotation will stop, and the component numbers in the call will also return to zero. However. net call component, if not written [try .. catch .. finally .. end try] And set [ obj. dispose () ] and [ OBJ = nothing ] are placed in finally, so the components in [Component Service] will not stop. This is because ASP and VB6 will automatically perform the resource reclaim action when the program is executed. resource collection in. NET must be manually executed by the program designer. Otherwise, GC must be started when the system resources are insufficient. Therefore, it is best to use using in. Net to declare that this object is used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.