使用vb建立DCOM服務器端及客戶端應用的詳細過程(2)

發表于:2007-05-25來源:作者:點擊數: 標簽:服務器用的DCOM客戶端建立
使用vb建立DCOM 服務器 端及客戶端應用的詳細過程(2) 本節介紹如何建立DCOM客戶端應用,及其注意事項。(本人使用的是西文版vb6) 1.打開vb,在"file"菜單單擊"New Project",選擇"Standard EXE"并單擊"OK". 2.在"Project"菜單, 單擊"References". 3.單擊"brow

使用vb建立DCOM服務器端及客戶端應用的詳細過程(2)

   本節介紹如何建立DCOM客戶端應用,及其注意事項。(本人使用的是西文版vb6)

 

   1.打開vb,在"file"菜單單擊"New Project",選擇"Standard EXE"并單擊"OK".

   2.在"Project"菜單, 單擊"References".

   3.單擊"browse",選擇"C:\DCOMDemo\Server\proDCOMDemoServer.exe",單擊"ok",
     并選中該引用.

   4.在工程里插入一個模塊,放置兩個CommandButton, 兩個textbox,以及三個label到form1上
     . 設置如下屬性:

   Control         Name              Property         Value
   ------------------------------------------------------------------
   Module          Module1           Name       modDCOMDemoClient     

   Form            Form1             Name             frmDCOMDemoClient
                                            Caption          DCOM Demo - Client

   CommandButton  Command1           Name             cmdServerTime
                                                       Caption          &Get Server Time

                  Command2              Name             cmdComputeNumbers
                                                Caption          &Compute Numbers

   Text Box        Text1              Name             txtX
                                              TabStop          True
                                              TabIndex         0

                   Text2                    Name             txtY
                                                 TabStop          True
                                                TabIndex         1

   Label           Label1            Name             lblAnswerAdd
                   Label2            Name             lblAnswerSubtract
                   Label3            Name             lblServerTime
 注意:現在還不要給工程更改名稱,即名稱仍為"PROJECT1"
 
   5.拷貝如下代碼到模塊里,(不是Form1上):


      Option Explicit

 

      Public oServer As New   _ proDCOMDemoServer.clsDCOMDemoServer


   6.拷貝如下代碼到frmDCOMDemoClient代碼窗口:


      Option Explicit
      Private Sub Form_Load()
           '設置文本框的初始化值.
            txtX.Text = "1"
            txtY.Text = "2"
      End Sub

      Private Sub txtX_GotFocus()
            txtX.SelStart = 0
            txtX.SelLength = Len(txtX.Text)
      End Sub

      Private Sub txtY_GotFocus()
            txtY.SelStart = 0
            txtY.SelLength = Len(txtY.Text)
        End Sub

      Private Sub cmdServerTime_Click()
           '獲取服務器端的程序,并將返回值顯示在lblServerTime標簽里.
           lblServerTime.Caption = oServer.ServerTime
      End Sub

      Private Sub cmdComputeNumbers_Click()
            lblAnswerAdd.Caption = oServer.AddNumbers _
                (CInt(txtX.Text), CInt(txtY.Text))
            lblAnswerSubtract.Caption = oServer.SubtractNumbers _
                (CInt(txtX.Text), CInt(txtY.Text))
      End Sub

      Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As _
                Integer)

            Set oServer = Nothing
      End Sub

 

   7.在"Project"菜單, 單擊"Project1 Properties."


   8.單擊"General",設置如下屬性:

   Project Type:             Standard EXE    

   Startup Object:           frmDCOMDemoClient 

   Project Description:      DCOM Demo Project - Client

 


   9.單擊"Make",設置如下屬性:

   Application Title:                  proDCOMDemoClient

 


   10.單擊"Compile",設置如下屬性:

   Compile to P-Code:       <Selected>

   11.單擊"OK"

   12.在"File"菜單, 單擊"Save Project As",保存的文件名稱如下所述:

   Directory         File       Filename           Extension
   ----------------------------------------------------------------
   C:\DCOMDemo\Client  Module       modDCOMDemoClient     .bas
                       Form1        frmDCOMDemoClient     .frm
                       Project      proDCOMDemoClient     .vbp


   13.按"F5"按鈕,測試客戶端應用

   14.測試完成,在"File"菜單, 單擊"Make proDCOMDemoClient.exe".

   15.將生成的exe文件保存到C:\DCOMDemo\Client

   16.關閉客戶端和服務器端應用.

 

                         <待續>

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97