MapObjects Connection

 

Creating MapObjects 2.0 applications in Borland C++ Builder 4.0

In order to use the Mapobjects ActiveX control successfully in BCB,
you will need a couple of patches from Borland's website:

Step 1:

Download Update #1

Update #1 must be installed before Update #2:

DESCRIPTION:

Among other fixes, this patch corrects existing ActiveX Client code, removing the underscore(s) on method and property names.

INSTRUCTIONS:

1. Run the EXE

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 following steps will step you through reimporting the MO2 control:

2. REMOVE the MapObjects 2.0 control:

  • under Component-->Install Packages... scroll down to 'User Components'
  • Click 'Edit', hit 'Yes' to cancelling the dialog box and opening the package
  • remove the MO2 files under 'Contains'
  • Compile the package
  • click ok and exit out of the package dialog box
  • say yes to save changes
  • (now if you go to the Active X tab on the toolbar, the MO2 control should be gone.)

3. ADDING M02 CONTROL:

  • go to Component --> Import ActiveX Control
  • Scroll to ESRI MapObjects 2.0
  • click 'Install'
  • hit OK, thereby Installing the MO2 libraries 'Into existing package'(dclusr40.bpk)
  • click 'Yes' to rebuild the package, hit OK
  • click ADD
  • Browse to 'C:\Program Files\Borland\CBuilder4\Imports' and open 'MapObjects2_TLB.cpp', hit OK
  • compile the package
  • exit out of the package dialog box and hit 'Yes' to save
  • exit out of Borland

4. 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.

Step 2:

Download Update #2:

INSTRUCTIONS:

1. Simply run the EXE

Step 3:

Create a new MapObjects 2/BCB 4.0 project: Be sure that you add the following line:

USEUNIT("C:\Program Files\Borland\CBuilder4\Imports\MapObjects2_TLB.cpp");

... after the line:

USEFORM("Unit1.cpp", Form1);

... in the project's CPP file. (i.e. project.cpp).

dotted line

Some Sample Code:

Adding a layer

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;
}