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