HOW TO

Create MapObjects 2.0 applications in Borland C++ Builder 4.0

Last Published: April 25, 2020

Summary

To use the Mapobjects ActiveX control successfully in Borland C++ Builder, you need to obtain and install a couple of patches from Borland.

Procedure



1. Click the link in the Related Information section below, and click the C++Builder 4 Patches link.

2. Download the appropriate Update #1 patch. Among other fixes, this patch corrects existing ActiveX Client code by removing the underscores on method and property names.

a. Run the EXE file.

After installing, be sure to reimport any Type Libraries or ActiveX controls. If the MO2.OCX has already been imported, it was probably added to the 'User Components' package (dclusr40.bpl). The remaining steps will let you reimport the MapObjects 2.0 control:

b. Remove the MapObjects 2.0 control:

· Under Component > Install Packages scroll down to User Components.
· Click Edit.
· Click Yes to cancel the dialog box and opening the package.
· Remove the MapObjects 2.0 files under Contains.
· Compile the package.
· Click OK and exit the Package dialog box.
· Click Yes to save changes.

The MapObjects 2.0 control should be gone from the Active X tab on the toolbar.

c. Add the MapObjects 2.0 control.

· Bring up Component > Import ActiveX Control.
· Scroll to ESRI MapObjects 2.0.
· Click Install.
· Click OK to install the MapObjects 2.0 libraries into the existing package(dclusr40.bpk).
· Click 'Yes' to rebuild the package.
· Click OK.
· Click ADD.
· Navigate to 'C:\Program Files\Borland\CBuilder4\Imports' and open MapObjects2_TLB.cpp.
· Click OK.
· Compile the package.
· Exit the Package dialog box.
· Click Yes to save changes.
· Exit Borland.

d. Delete all *.csm, and *.#nn files (compiler-generated files, where "nn" indicates numbers). You'll find these files either in the directory that contains your project or in your CBuilder4\Lib directory.

Note:
Make sure you install this before Update #2.

3. Download the appropriate Update #2. Run the EXE to install.

4. Create a new MapObjects 2/BCB 4.0 project: Be sure you add the following line in the project's CPP file (project.cpp):

USEUNIT("C:\Program Files\Borland\CBuilder4\Imports\MapObjects2_TLB.cpp");
... after the line:
USEFORM("Unit1.cpp", Form1);


This is a sample code to add a layer:

Code:
IMoMapLayerDisp lyr;
IMoDataConnectionDisp dc;
dc = (IDispatch*)CreateOleObject("MapObjects2.DataConnection");
AnsiString path = "C:\\ESRI\\Mapobjects2\\samples\\data\\usa";
dc.Database = WideString(path).Detach();
if ((bool)dc.Connect())
{
lyr = (IDispatch*)CreateOleObject("MapObjects2.MapLayer");
lyr.GeoDataset = dc.FindGeoDataset(WideString("Capitals").Detach());
Map1->Layers->Add(lyr);
}

IMoMapLayerDisp mylyr;
IMoLayersDisp mylyrs;
IMoRecordsetDisp recset;
IMoFieldsDisp flds;
IMoPolygonDisp shape;
IMoRectangleDisp rect;
AnsiString query;
query = "STATE_NAME ='" + Edit1->Text + "'";
mylyrs = Map1->Layers;
mylyr = (IDispatch*)CreateOleObject("MapObjects2.MapLayer");
mylyr = (IDispatch*)mylyrs.Item(WideString("States").Detach());
recset = (IDispatch*)mylyr.SearchExpression(WideString(query));
if(!(bool)recset.EOF)
{
flds = (IDispatch*)recset.Fields;
shape = (IDispatch*)CreateOleObject("MapObjects2.Polygon");
shape = (IDispatch*)(flds.Item("Shape")->Value);
Map1->FlashShape(shape, 3);
rect = (IDispatch*)CreateOleObject("MapObjects2.Rectangle");
rect = shape.Extent;
rect.ScaleRectangle((1.5));
Map1->Extent = (IDispatch*)rect;
}

Article ID:000004250

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic