Access Violation when retrieving Duration/Distance

We have a component in our application where we show a route. Now we want to show the duration and distance for this route.

As i found out, this should work via the OnRouteRetrievedDirectionsData-Event. In general, this looks good. AEventData is holding the information we need.

I tried to get tha data out of ADirectionsData as it is more convenient. But i always get an AccessViolation when trying to access .Distance.

I am using C++ Builder 13 with the latest TMS.FNC.Maps-Package.

void __fastcall TFormGoogleMapsAnfahrtsbeschreibung::wgmRouteRetrievedDirectionsData(TObject *Sender, TTMSFNCMapsEventData *AEventData,
		  TTMSFNCGoogleMapsDirectionsData ADirectionsData)
{
	auto routes = ADirectionsData.Routes;
	if (routes.Length == 0)
		return;

	auto legs = routes[0].Legs;
	if (legs.Length > 0)
	{
		int d = legs[0].Distance;
		ShowMessage(d);
	}
}
//---------------------------------------------------------------------------

Hi,

We are not aware of any issues regarding the AddDirections in combination with the OnRetrievedDirectionsData event functionality in TTMSFNCGoogleMaps.

Please provide the following info so I can further investigate this issue.

  • Is the Directions API enabled in the Google Developer Console for the Google API key used?
  • Is the route displayed on your map?
  • Does this happen for any route or only for a specific route?
  • Do you see any JavaScript errors? (Click the map at runtime, press F12 and select the Console tab)

Seems to be only a Problem with C++ Builder and the 32bit-Target (CLANG-based compiler). Changing the Target to 64bit (Modern) works as expected.
In Delphi both Targets work fine.

I also tested it on a second Machine.

Minimal Code to reproduce:

void __fastcall TForm3::Button1Click(TObject *Sender)
{
	this->TMSFNCGoogleMaps1->AddDirections(L"Hunding", L"Osterhofen", true, true);
}
//---------------------------------------------------------------------------

void __fastcall TForm3::TMSFNCGoogleMaps1RetrievedDirectionsData(TObject *Sender, TTMSFNCMapsEventData *AEventData, TTMSFNCGoogleMapsDirectionsData ADirectionsData)
{
	ShowMessage(ADirectionsData.Routes[0].Legs[0].Duration);
	ShowMessage(ADirectionsData.Routes[0].Legs[0].Distance);
}
//---------------------------------------------------------------------------
  • Yes
  • Yes
  • Happens on any Route
  • Yes, see below

Can you please try setting the Use 'classic' Borland compiler option to true in the Project options>C++ Compiler?
This should make your code work as expected.

This works indeed with my Sample-Project but isn't an option for our Application as we ware using newer C++ Functions which are not available with older Compilers.

We are investigating a potential solution and will provide an update as soon as possible.

1 Like