Free a form with a Marker selected makes app crash (MapView)

341 Views Asked by At

If any marker is selected on a MapView using this:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := TCloseAction.caFree;
end;

The app crash right after the form is closed.

But, if using this:

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
MapView1.DisposeOf;
finally
Action := TCloseAction.caFree;
end;
end;

The app doesn't crash, but an Access violation message is fired after the form is closed. What may be causing this? There is someway to avoid it?

Best regards

1

There are 1 best solutions below

0
Maurício Lima On

Edit:

Actually I was adding markers to the map in the wrong way. You cannot add TMarkerDescriptor like this:

MapView1.AddMarker(MyMarker1);  // MyMarker is a TMapMarkerDescriptor

You must use a TMapMarker like this:

MMyMarker1 := MapView1.AddMarker(MyMarker1); // MMyMarker1 is a TMapMarker and MyMarker1 is a TMapMarkerDescriptor

However, you must use:

MMyMarker1.DisposeOf;

on OnFormClose for every marker you add to the map to avoid crash, like this:

procedure TForm69.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
MMyMarker1.DisposeOf;
finally
 Action := TCloseAction.caFree;
end;
end;