Community of VE/MapPoint Users and Developers
This is a discussion on How to close MapPoint applications correctly? within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hello, I'm about to develop an Delphi 5 application using MapPoint 2006. The problem is that when I close ...
| |||||||
| Register | Blogs | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| How to close MapPoint applications correctly? I'm about to develop an Delphi 5 application using MapPoint 2006. The problem is that when I close my application, I get an EAccessViolation in Module ole32.dll at 0008D65E, then a message "Runtime error 216 at 00003134". Does someone of you have the same problem and know how to solve it? Perhaps I do not close my application correctly... have I to free any objects before closing the application? What do I have to do before closing my app? I'm looking forward to get some help... For your information: On my form there is a TOlecontainer. I initialize my application with the following code: Code: procedure TfrmData2Map.FormActivate(Sender: TObject);
var
vGuid : TGuid;
begin
OleContainer.CreateObject('MapPoint.Map.EU.13', False);
OleContainer.DoVerb(1);
OleContainer.OleObjectInterface.GetUserClassID(vGuid);
FMap := IDispatch(OleContainer.OleObject) as _Map; // global variable of type _Map
mpApplication.Units := geoKm;
end; Dietmar |
| |||
| Re: How to close MapPoint applications correctly?
Hi Dietmar, Runtime error 216 is the same as a General Protection Fault. A GPF is most often caused by writing to something that doesn't belong to you (like a memory or variable overwrite). It can also be a stack error, meaning you write over the bounds of variables placed on the stack. What if you open your application and close it ? I mean nothing more that a new application that open a map and do nothing ? Do you still have the error ?
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: How to close MapPoint applications correctly?
Hello Wilfried, I tried only to open and then close my application. The same error occurs. Now I created a new application only with the OleContainer on the form and loaded MapPoint in it the same way I described in my previous post (without setting mpApplication.Units) It worked without error. After that I put a MapPoint Application object on the form and the error was there again. It seems to have something to do with the mappoint application object... But why? Another question is why I need the MP Application object at all? It seems not to be linked to the global FMap variable... So I think setting the mpApplication.Units (for example) has no effect on the FMap object. Best wishes Dietmar |
| |||
| Re: How to close MapPoint applications correctly?
I did a small test (Delphi7) and it works. This is the mappoint unit: Code: unit uMP;
interface
uses
Controls, Classes, OleCtnrs, MapPoint_TLB;
type
TMP = class
private
FMap: _Map;
OleContainer: TOleContainer;
public
constructor Create(AOwner: TComponent; ParentControl: TWinControl);
destructor Destroy; override;
property Map: _Map read FMap;
end;
implementation
{ TMP }
constructor TMP.Create(AOwner: TComponent; ParentControl: TWinControl);
var
Guid: TGuid;
begin
OleContainer := TOleContainer.create(nil);
OleContainer.Parent := ParentControl;
OleContainer.Align := alClient;
OleContainer.CreateObject('MapPoint.Map.EU.13', False);
OleContainer.DoVerb(1);
OleContainer.OleObjectInterface.GetUserClassID(Guid);
FMap:= IDispatch(OleContainer.OleObject) as _Map;
FMap.Application.Units := geoKm;
end;
destructor TMP.Destroy;
begin
OleContainer.DestroyObject;
OleContainer.Free;
inherited;
end; Code: procedure TMain.FormActivate(Sender: TObject); begin MP := TMP.Create(Self, MPPanel); end; procedure TMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin MP.Free; end;
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: How to close MapPoint applications correctly?
Hello Wilfried, thanks, your code works! Do you use MapPoint in every of your application like that? The only question is if I have to place a separate Application Object (map point application!) on the form... or if it is ok to access the application object by FMap.Application, too. Regards, Dietmar |
| |||
| Re: How to close MapPoint applications correctly?
Hi Dietmar, FMap.Application is OK. No I have several solutions in Delphi but it is not always the same. I also have a component for MapPoint which I use in a few applications (Delphi 5, but should work in D7+ as well).
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: How to close MapPoint applications correctly?
Hi! Thanks, now I use such a MapPoint class in my Delphi App. The app now runs stable without errors. But there is another problem I will tell you now: In my application there is (simplified for you Now I found out that the Map.SaveAs method doesn't work anymore - the map is simply not saved. I found out, that, if I place a (MP)Application object from the Delphi Toolbar on the form AND set the MP.FMap to its ActiveMap property AND set mpApplication.AutoConnect to true (in Delphi IDE), the map will be saved: Code: procedure TMain.FormActivate(Sender: TObject); begin MP := TMP.Create(Self, MPPanel); MP.FMap := mpApplication.ActiveMap; // mpapplication is the object on the form end; What I want is to save the map in .ptm file AND see map changes (zooming e.g.) on the screen! Has someone an idea how to achieve this? Regards, Dietmar |
| |||
| Re: How to close MapPoint applications correctly?
Hi, I'm not sure I understeand the problem. Can you tell (again) when the SaveAs work and when not ?
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
| |||
| Re: How to close MapPoint applications correctly?
Ok, I will try to explain it. I wrote a simplified program. First, look at my code, there are 2 units: This is the Main Unit (see also the attachment to the post): Code: unit MainU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, MapPntU, MapPoint_TLB, OleServer;
type
TForm1 = class(TForm)
pnlMapPoint: TPanel;
Panel1: TPanel;
btnChangeViewAndSave: TButton;
Label1: TLabel;
mpApplication: TApplication;
procedure FormShow(Sender: TObject);
procedure btnChangeViewAndSaveClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
MPnt: TMP;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormShow(Sender: TObject);
begin
MPnt := TMP.Create(Self, pnlMapPoint);
// Note: If I set MPnt.FMap to the mpApplication.ActiveMap property, the map
// will be saved. BUT change of view (zooming to Location = London, UK)
// IS NOT visible on screen (in the oleContainer), only in the .ptm file.
// If you remove the following line, change of view IS visible on screen,
// but the map isn't saved. Try it...
MPnt.FMap := mpApplication.ActiveMap;
Self.WindowState := wsMaximized;
end;
procedure TForm1.btnChangeViewAndSaveClick(Sender: TObject);
var
TestLoc: Location;
begin
// Example: Go to a Location and zoom (only to change the view)
// Changing the view is only visible if MPnt.FMap is not set
// to mpApplication.ActiveMap!
TestLoc := MPnt.FMap.GetLocation(51.5000, 0.5000, 0);
TestLoc.GoTo_;
MPnt.FMap.ZoomIn;
MPnt.FMap.ZoomIn;
MPnt.FMap.ZoomIn;
// The map will only be saved if MPnt.FMap is set to mpApplication.ActiveMap!
MPnt.FMap.SaveAs('c:\example_map.ptm', geoFormatMap, true);
end;
end. Code: unit MapPntU;
interface
uses MapPoint_TLB, Windows, SysUtils, Classes, Controls, OleServer, OleCtnrs;
type
TMP = class
constructor Create(AOwner: TComponent;ParentControl:TWinControl);
destructor Destroy;
private
OleContainer1: TOleContainer;
locNorthPole:Location;
locSantaCruz:Location; //Center of western hemisphere
Pi, dblHalfEarth, dblQuarterEarth:double;
public
FMap: _Map; // the active map
end;
implementation
constructor TMP.Create(AOwner: TComponent; ParentControl:TWinControl);
var
vGuid: TGuid;
begin;
OleContainer1:=TOleContainer.create(aowner);
OleContainer1.Parent:=ParentControl;
OleContainer1.Align := alClient;
OleContainer1.CreateObject('MapPoint.Map.EU.13',False);
OleContainer1.DoVerb(1);
OleContainer1.OleObjectInterface.GetUserClassID(vGuid);
FMap:= IDispatch(OleContainer1.OleObject) as _map;
locNorthPole:=fmap.GetLocation(90,0,0);
locSantaCruz:=fmap.GetLocation(0,-90,0);
dblHalfEarth:=fmap.Distance(locNorthPole, fmap.GetLocation(-90, 0,0));
dblQuarterEarth:=dblHalfEarth/2;
Pi:=3.14159265358979;
end;
destructor TMP.Destroy;
begin
FMap:=nil;
OleContainer1.DestroyObject;
end;
end. On the form there is a Map Point Application Object (you get it from the Delpi Toolbar, e.g. under "ActiveX"). It has a AutoConnect property which is set to TRUE. FIRST scenario: (In the first scenario the mpApplication object on the form is not needed.) In the FormShow event procedure there is following line - Remove it! Or comment it out: Code: // MPnt.FMap := mpApplication.ActiveMap; SECOND scenario: Now we need mpApplication object and the code line you comment out before: We set the MPnt.FMap to the ActiveMap property of our mpApplication object: Code: MPnt.FMap := mpApplication.ActiveMap; (But only if you open the .ptm file with the original Microsoft MapPoint Application, you see that zooming was performed) I believe that in the SECOND scenario there are two different maps - one in the oleContainer and the other one will be saved. Or not? I hope you understood the problem. I want to have a saved .ptm file AND see changes of view on my oleContainer! How can I do that? Regards Dietmar Last edited by doMapPoint; 05-24-2007 at 03:10 AM. Reason: added project zip file |
| |||
| Re: How to close MapPoint applications correctly?
Hi, You have 2 instance of MapPoint running (please check in task manager). One because you drop the component on a form and a second one you create yourself. The problem is that you assign the Activemap from the one to the active map of the other. So what you see is the map from the other application. So that is wy commenting out the line will let you see the right changes. You can as well remove the component and then check task manager there will be only one instance of MapPoint running. However I talk a lot because that does not solve the problem wy it is not saved. I will try to try it myself later today if I find some spare time.
__________________ rgds, Wilfried Mestdagh www.mestdagh.biz MapPoint coding demo Order MapPoint 2009 with Routing and User Tools Spreadsheet |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| MapPoint OCX SLOW on close. | Gianmaria | MapPoint 2006/2009 Discussion | 3 | 01-31-2007 12:32 PM |
| How to properly close mappoint control | Anonymous | MapPoint 2006/2009 Discussion | 1 | 03-03-2005 08:05 AM |
| Mappoint has encountered a problem and needs to close | Anonymous | MapPoint 2006/2009 Discussion | 4 | 05-05-2004 03:40 PM |
| Correctly Mapping NMEA Data | Anonymous | MapPoint 2006/2009 Discussion | 1 | 03-18-2004 01:28 PM |
| Pause MapPoint Display (prevent close) | Anonymous | MapPoint 2006/2009 Discussion | 0 | 10-29-2002 05:56 PM |
Chalet Ski Holidays
Want to book chalet ski holidays? Holiday Hypermarket doesn't just make booking easy but also gives you access to deals from leading travel brands.
Online Travel Agent
Travel Counsellors is a Queen's Award winning online Travel Agent. Book your travel online with one of our agents.
Canada Flights
Canada flights are great value flights when you visit dealchecker.co.uk first. Full of surprises, Canada is simply the most astonishingly beautiful country in the world.
Holidays to Antigua
The Holiday Place has fantastic deals on holidays to Antigua. Visit our website to view special offers on holidays to the Caribbean.
Cheap Egypt Holidays
Pick up a bargain cheap Egypt holiday online when you visit ulookubook.com. Just check out our tips to make sure you book at the right time to get a great holiday for a great price. Finding cheap Egypt holidays can be simple when you know how.
Holidays
At Travel.co.uk the options for holidays are endless. Do some online comparison shopping!
Cheap Florida Holidays
You thought American holidays were expensive? No ways! Affordable holidays to Florida, only at On The Beach.