| |
t e m p o r a l |
d o o r w a y |
|||||||||
Using MapX with C++ Builder |
|||||||||||
|
MapX can be easily used with C++ Builder. C++ Builder understands OLE controls, so you can easily install it on the Component Palette - just pick Component / Install and then click ActiveX and pick the MapX control from the list of available OCX. However, this is only the beginning. First, you need the Microsoft Foundation Classes (MFC) header files and a link library. Why? Because the C++ MapX wrapper class supplied by MapInfo is based on classes from the MFC. Currently, this means you need a copy of Borland C++ 5.02. Once you have that, you need to make certain modifications to the MFC and C++ Builder header files. These modifications will allow you to compile MFC and VCL (Borland's Visual Component Library) in the same program. Before using the MapX header files, you must also make some changes there: In Mapx\Samples\cpp find stdafx.h and comment out
and
Otherwise you will receive errors concerning the DAO header files. Since you do not need DAO to use C++ Builder, this is safe to exclude. Once that is done, you need to understand a little about how Microsoft's OLE Controls work in order to see why the next step is needed. Every OLE Control implements at least two interface classes: IUnknown (which allows an application to determine what services (properties and methods are offered by an OCX or its subordinate objects) and IDispatch (which allows an application to call on the services of an OCX or its subordinate objects). When you install the MapX component into C++ Builder, C++ Builder uses the IUnknown interface to contact the control and determine its properties and methods. From this information, it generates an .HPP file, which it stores in ($BCB)\LIB However, except for MapX properties which are basic types, the resulting header file assumes the type of a property is a System::Variant. This includes properties like Layers, Layer, Datasets, etc. The System::Variant returned by referencing the property contains an IDispatch * for the underlying object. The MapX header file (MapX\Samples\CPP\MapX.h) contains for each subordinate object contains a constructor for that object which accepts an IDispatch *. Thus, when you need to use a MapX object such as Datasets, you must construct it as follows:
Note that you cannot create a CMapX object AT ALL. You must use the TMap created when you drop the MapX on a form - this is the C++ Builder representation of the MapX control. In cases where you are creating a MapX subordinate object yourself, you need to cause it to create its own internal IDispatch *. That is done by calling CreateDispatch on the object and passing the class ID from the Windows Registry. This is made easier by the provision in most MapX subordinate object classes of a function called Classid(). So use the following form:
Failure to do this will cause your program to experience an Access Violation the moment you try to do anything to the object. At this point, you are ready to make use of the MapX control in your application. Consult my article on Data Binding in C++ to understand how to plot points from database tables in a MapX control used by your application. |
|||||||||||
|
Copyright © 2004 by Mark
Cashman (unless otherwise indicated), All Rights Reserved
|