Upload
bangalore-techie
View
135
Download
0
Embed Size (px)
Citation preview
The presentation will begin at 9AM Pacific Time
Presenter: Sally Swenson ESRI Redlands, California
Migrating to VB .NET
Seminar overviewTopics include
Moving from VB6 to VB .NETResolving tricky VB .NET issuesDistributing a VB .NET application
FormatEach topic followed by review and question and answer periodPresentation includes software demonstrations
Copyright © 2003 ESRI. All rights reserved.
Moving from VB6 to VB .NET
Copyright © 2003 ESRI. All rights reserved.
Reasons for migratingApplication requirements
Language options (VB and C#)Development environment
Built-in APIIntegrated HelpFully object oriented
Can't buy VB6 off the shelfVB6 is still available.ESRI Technical Article 24963 (http://support.esri.com)
ESRI requires migration to VB .NET?
Copyright © 2003 ESRI. All rights reserved.
Reasons for migratingApplication requirements
Language options (VB and C#)Development environment
Built-in APIIntegrated HelpFully object oriented
Can't buy VB6 off the shelfVB6 is still available.ESRI Technical Article 24963 (http://support.esri.com)
ESRI requires migration to VB .NET? No, ESRI does NOT require VB .NETSupports VB6, or any language that supports COM
Copyright © 2003 ESRI. All rights reserved.
More reasons for migrating Advanced features
ArcWeb ServicesDebugging
Beyond ICommand and IToolNew controls
DockingAnchoring
Copyright © 2003 ESRI. All rights reserved.
Installing ArcGIS and VB .NETVisual Studio .NET 2002 or 2003
VB .NET onlyC++ and C#, if needed
ESRI ArcObjects .NET Developer KitContains API for ArcObjects development
Copyright © 2003 ESRI. All rights reserved.
Adding assemblies...\ArcObjects Developer Kit\Dotnet\AssembliesESRI.ArcObjects.Core
DirectivesImports ESRI.ArcObjectsesriCore.IFeatureLayer > Core.IFeatureLayer
Getting started
Object Libraries (VB6) Assemblies (VB .NET)esriCore.olb Core
esriMx.olb Mx
esriSpatialExt.olb SpatialExt
esriStreetMap.olb StreetMapExt
esriSurveyCoreExt.olb SurveyCoreExt
Copyright © 2003 ESRI. All rights reserved.
Using the ESRI Add-InsESRI Interface Implementer
Stubs out the implementation code wrapper linesNot needed for Visual Studio .NET 2003
ESRI Component Category RegistrarWorks with ESRI.ArcObjects.Samples.CatIDS assemblyAutomates component category registration
Copyright © 2003 ESRI. All rights reserved.
Software demonstration
Copyright © 2003 ESRI. All rights reserved.
Topic review and Q & AWhy migrate to VB .NET?InstallationAssemblies and DirectivesESRI Add-InsCreating projects in VB .NET
Copyright © 2003 ESRI. All rights reserved.
Resolving tricky.NET issues
Copyright © 2003 ESRI. All rights reserved.
Option statementsOption Explicit
On, by default Option Strict
Off, by defaultAllows narrowing conversion
On, recommendedPrevents narrowing conversionType safety
Copyright © 2003 ESRI. All rights reserved.
Option Strict: query interface
Option Strict On Query Interface for ILayer
Option Strict Off Query Interface for ILayer
! Option Strict On disallows implicit conversions from 'ILayer' to 'IFeatureLayer'
featlayer = _CType(doc.focusmap.layer(0), IFeatureLayer)
Solution: Type cast
featlayer = doc.focusmap.layer(0)
Copyright © 2003 ESRI. All rights reserved.
Exception handlingReplaces VB6 error handlingIf omit, beware!
Embedded resource is case sensitiveIf error, no warning plus no icon on interface
AssemblySystem.Runtime.InteropServices
TryGetManifestResourceStream("prj.zoomin.bmp")
Catch ex As ExceptionMsgBox _(ex.Message & "Error: " & [GetType]().Name)
Finally' Code you put in Finally will always execute
End Try
Copyright © 2003 ESRI. All rights reserved.
Object by defaultIn VB6: multiple one-line declarations of same data type
In VB .NET, multiple one-line declarations of same data type
No more Variant
Dim i, j, k As Integer
Dim i, j, k As Integer
i = 11 ' Integerj = 12 ' Variantk = 13 ' Variant
i = 11 ' Integerj = 12 ' Integerk = 13 ' Integer
Copyright © 2003 ESRI. All rights reserved.
Garbage collectionIn COM, need to free memory
In VB .NET, garbage collection is indeterminateobj = Nothing
Add the namespace
Release memory in the method that uses obj
Always release in a loop until ival = 0Dim ival As IntegerDo Until ival = 0ival = Marshal.ReleaseComObject(obj)
Loop
Imports System.Runtime.InteropServices
Marshal.ReleaseComObject(obj)
Copyright © 2003 ESRI. All rights reserved.
Summary of changes with VB .NET
Visual Basic 6 Visual Basic .NETSet pAMap = pMxDoc.FocusMap AMap = MxDoc.FocusMap
Option Explicit Option Strict
DLL Assembly
Class module COM class
GUID created at compile GUID created in code
Error handling Exception handling
Debug.Print Debug.WriteLine
Class_Initialize / Terminate Class Constructor / Destructor
Copyright © 2003 ESRI. All rights reserved.
Software demonstration
Copyright © 2003 ESRI. All rights reserved.
Topic review and Q & AOption StrictException handlingGarbage collectionChanges with VB .NET
Copyright © 2003 ESRI. All rights reserved.
Distributing an application
Copyright © 2003 ESRI. All rights reserved.
Client requirements Full installation of ArcGIS
Including licenseArcObjects .NET Developer Kit
Assemblies
Copyright © 2003 ESRI. All rights reserved.
Client requirements Full installation of ArcGIS
Including licenseArcObjects .NET Developer Kit
AssembliesVB .NET Framework (~500MB)
Already installed on newer machines
Copyright © 2003 ESRI. All rights reserved.
COM component requirementsWindows registration
VB .NET Setup and Deployment wizard handles registrationAlternative: regasm.exe
Copyright © 2003 ESRI. All rights reserved.
Topic review and Q & AClient requirementsCOM component requirements
Copyright © 2003 ESRI. All rights reserved.
For more information
ArcObjects Onlinehttp://arcobjectsonline.esri.com
Getting Started >The .NET Framework
ESRI Instructor TrainingAdvanced ArcObjects Component Development I (VB)
Advanced ArcObjects Comp Dev II (.NET)
ESRI PressGetting to Know ArcObjects: Programming ArcGIS with VBA
Microsoftmsdn.microsoft.com/vbasic
Copyright © 2003 ESRI. All rights reserved.