HOW TO

Pass the Application object to a VB Form

Last Published: April 25, 2020

Summary

When developing a VB ActiveX DLL project that contains a Form, the Form needs to know about ArcMap. In that case, it is required to pass an Application object to the Form.

Procedure

Instructions provided describe how to Pass an Application object to a VB Form. When creating the Visual Basic ActiveX .DLL project in Step 1:

- Name the Class 'clsApp'
- Name the Project 'AoDemo'
- In Project Properties, enter 'ArcObjects Application' as the Project Description

- Save the class as clsApp.cls
- Save the project as AoDemo_clsApp.vbp
- Compile the .DLL as AoDemo_clsApp.dll

  1. Create a new Visual Basic ActiveX .DLL project that implements ICommand.
    <a href='http://support.esri.com/en/knowledgebase/techarticles/detail/23923' target='_blank'>How To: Implement ICommand in Visual Basic</a>
  2. Add a Form to the project and name the Form frmApp.
  3. In the General Declarations section of the frmApp code module, declare a module-level reference to the Application.

    Code:
    Option Explicit
    Private m_pApp As IApplication

  4. In frmApp, add Public Get and Set properties for the Application.

    Code:
    Public Property Set Application(pApp As IApplication)

    Set m_pApp = pApp
    ' *************************
    ' Add your custom code here
    ' *************************
    End Property

    Public Property Get Application() As IApplication
    Set Application = m_pApp
    End Property

  5. In the Class Module clsApp, rewrite the implementation code for the OnCreate method of ICommand:

    Code:
    Private Sub ICommand_OnCreate(ByVal hook As Object)

    Set frmApp.Application = hook

    End Sub

  6. In Class_Terminate of clsApp, remember to release the reference to the application.

    Code:

    Private Sub Class_Terminate()
    Set frmApp.Application = Nothing
    Unload frmApp
    End Sub


Article ID:000005779

Software:
  • ArcMap 9 x
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic