MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




How to close MapPoint applications correctly?

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


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  9 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 05-14-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Location: Germany
Posts: 13
How to close MapPoint applications correctly?

Hello,

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;
Best wishes
Dietmar
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 05-14-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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 ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 05-15-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Location: Germany
Posts: 13
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 05-15-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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;
This is the form:

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;
So there must be some other difference somewhere.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 05-15-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Location: Germany
Posts: 13
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 05-17-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 05-23-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Location: Germany
Posts: 13
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) a button - when I click this button, Locations are created and it will be zoomed to the Locations. Zooming is visible on the screen (of course). Then I call the SaveAs method.
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;
But doing so, my zooming etc. isn't visible on screen anymore (but zooming etc. has effect on the saved map!).

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 05-23-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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 ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 05-24-2007
Junior Member
Yellow Belt
 
Join Date: May 2007
Location: Germany
Posts: 13
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.
This is the unit containing a mapPoint class:
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.
So, now I try to explain 2 scenarios:

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;
Then run the app and click on the button. You see that the map zooms to London. But you won't find a saved .ptm file - the map is not saved.

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;
Run the app and click on the button. The map now is saved! You find a .ptm file! But you don't see the change of view on your screen!
(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
Attached Images
File Type: jpg MainUnitForm.jpg (27.0 KB, 6 views)
Attached Files
File Type: zip MapPointExample_Project.zip (189.3 KB, 18 views)

Last edited by doMapPoint; 05-24-2007 at 03:10 AM. Reason: added project zip file
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10 (permalink)  
Old 05-24-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,017
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/how-close-mappoint-applications-correctly-5879.html

Posted By For Type Date
Extending the MapPoint ActiveX Control - Pt. I - MapPoint Articles - MP2K Magazine This thread Refback 05-22-2007 08:55 AM
A More Compact Method for Obtaining Lat/Long - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:40 PM
Improving On The MapPoint Geocoding Algorithm - Pt. I - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:40 PM
Creating a Grid Over Iraq In MapPoint - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:40 PM
Programming MapPoint with the .NET Framework, Delphi examples, MapPoint .NET, MDB Circus - MP2K Update Archives - MP2K Magazine This thread Refback 05-14-2007 01:40 PM
Using MapPoint In Delphi - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:33 PM
Snap to a Road - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:24 PM
Delphi Address Verifier - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:22 PM
Using MapPoint In Delphi - MapPoint Articles - MP2K Magazine This thread Refback 05-14-2007 01:20 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

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


All times are GMT -5. The time now is 01:16 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5
MP2K Magazine
Visitor Map

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47