Using MapPoint In Delphi
Jack Melgers explains how developers can go about using MapPoint within Delphi and provides several code snippets
From the many postings, it's now commonly known that you can not use the MapPoint 2002
ActiveX-control in Delphi, you´ll end up with the message: 'No such interface supported'.
Nevertheless, there are other ways for using MapPoint 2002 in Delphi and below I´ll
give some comments.
1) Importing MapPoint_TLB
Start by importing the Type Library (TLB) in Delphi. Choose 'Import Type Library',
select 'Microsoft MapPoint 9.0 Object Library', tick 'Generate Component Wrapper' and
then click 'Install'. This will compile and build a Delphi package and as a result three
MapPoint components will appear on the ActiveX-tab of the Component Palette: TApplication,
TMap and TMapPointUtilities.
2) Using MapPoint TApplication as a component on the form
Create a new Delphi application and drop the MapPoint component TApplication on the
Delphi-form. Make it visible in the Activate-event of the form. This will execute
MapPoint in a separate window:
Doing so, you can access the MapPoint Object Model and start developing. For instance,
get the ActiveMap and zoom to a location:
3) Creating a MapPoint.Map in an OleContainer
If you don´t want MapPoint to execute as a separate application you can use TOleContainer
in Delphi. Create a new Delphi application and drop an OleContainer component on the form,
add MapPoint_TLB in the 'uses' section and add the following code to Activate-event of the form:
('MapPoint.Map.EU.9' is the OleClassName for the European edition of Mappoint and
'FMap' is a global variable of type _Map).
Note in general: If you can not properly access the MapPoint Application in Delphi, the
cause maybe a conflict with the Delphi Application. Therefore, open the 'Mappoint_TLB.pas'
and find the declaration of CoClasses and rename 'Application = _Application' to, for
instance, 'Application1 = _Application'.
4) Accessing MapPoint Add-ins
If you have developed an Add-in (the MapPoint-Help gives a step-to-step explanation how to
create an Add-in with Visual Basic) you can access it from Delphi.
Create a new Delphi application and drop a MapPoint TApplication on the form.
Declare the global variables:
- FAddIns : AddIns;
- FMyAddIn : OleVariant;
Connect to the add-in in the Activate-event of the form:
And disconnect in the Close-event of the form:
Now in the Delphi-application you can access methods in the Add-in. For instance:
You can also pass parameters to the Add-in. See the following example for passing two
parameters of type integer: