Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

How to close MapPoint applications correctly?

This is a discussion on How to close MapPoint applications correctly? within the MapPoint Desktop 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 my ...

  1. #1
    doMapPoint is offline 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

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    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 ?

  3. #3
    doMapPoint is offline 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

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    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.

  5. #5
    doMapPoint is offline 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

  6. #6
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

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

  7. #7
    doMapPoint is offline 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

  8. #8
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    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 ?

  9. #9
    doMapPoint is offline 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 Attached Images
    Attached Files Attached Files
    Last edited by doMapPoint; 05-24-2007 at 04:10 AM. Reason: added project zip file

  10. #10
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    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.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. MapPoint OCX SLOW on close.
    By Gianmaria in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 01-31-2007, 01:32 PM
  2. How to properly close mappoint control
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-03-2005, 09:05 AM
  3. Mappoint has encountered a problem and needs to close
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 4
    Last Post: 05-05-2004, 04:40 PM
  4. Correctly Mapping NMEA Data
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-18-2004, 02:28 PM
  5. Pause MapPoint Display (prevent close)
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 10-29-2002, 06:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96