Detect if Routecalculator are Requests finished

Is it possible to detect if Routecalculator finished with all Requests?

When fill up the Routes i need an Trigger if all 3 Routes Complete and
the procedure DoSomething can work.

begin
....
Routecalculator1.CalculateRoute('Berlin','München',nil,'Route1') ;
Routecalculator1.CalculateRoute('München','Hannover',nil,'Route2') ;
Routecalculator1.CalculateRoute('Hannover','Berlin',nil,'Route3') ;

for I := 0 to Routecalculator1.Routes.Count -1 do
begin
DoSomething;
end;
....
end;

At the Moment the Routes are Calculated in the Backkground and DoSomething will not run,
because Routecalculator1.Routes.Count are 0;

Best Regards Jens

Please note that the OnCalculateRoute event is triggered after the CalculateRoute call is finished.
You'll have to manually keep track to know if all requests have finished.

Do you happen an Example ?

I have mismatch at my brain and do not how to solve the Problem.

I try differnt ways as use callback .. OnCalculateRoute , OnGetRouteDirections and so on.
But i can´t find a way to wait if all Routes are complete .

Here is an example using the OnCalculateRoute event:

  public
    { Public declarations }
    Route1Finished: Boolean;
    Route2Finished: Boolean;
    Route3Finished: Boolean;
  end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Route1Finished := False;
  Route2Finished := False;
  Route3Finished := False;

  TMSFNCRouteCalculator1.CalculateRoute('Berlin','München',nil,'Route1') ;
  TMSFNCRouteCalculator1.CalculateRoute('München','Hannover',nil,'Route2') ;
  TMSFNCRouteCalculator1.CalculateRoute('Hannover','Berlin',nil,'Route3') ;
end;

procedure TForm1.TMSFNCRouteCalculator1CalculateRoute(Sender: TObject;
  const ARoute: TTMSFNCRouteCalculatorRoute);
begin
  if ARoute.ID = 'Route1' then
    Route1Finished := True;
  if ARoute.ID = 'Route2' then
    Route2Finished := True;
  if ARoute.ID = 'Route3' then
    Route3Finished := True;

  if Route1Finished and Route2Finished and Route3Finished then
  begin
    Route1Finished := False;
    Route2Finished := False;
    Route3Finished := False;
    TTMSFNCUtils.Log('do something');
  end;
end;

Oh Man, so simple :frowning: .. Perfect it works :call_me_hand:
Sorry, but after 5 days of looking for a solution, my thinking was too complex

Happy to help!

Sorry but one Question,

if in the sample Route3 (Adressdata) invalid like
"TMSFNCRouteCalculator1.CalculateRoute('xvdve','pepfdlded',nil,'Route3') ;"

then it comes never to
"if ARoute.ID = 'Route3' then Route3Finished := True;"

Is it possible to test the Adressdata for valid before Execute the CalculateRoute or is
an Event / Trigger or something in the OnCalculateRoute or OnGetDirections to check if the Route are created or not?

You can test the if the StartAddress and/or EndAddress is valid by executing a separate GetGeocoding request before calling CalculateRoute.
If the OnGetGeocoding event returns zero items, this means the provided address was invalid.

Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TMSFNCRouteCalculator1.GetGeocoding('Berlin', nil, 'Geo1');
  TMSFNCRouteCalculator1.GetGeocoding('xdve', nil, 'Geo2');
end;

procedure TForm1.TMSFNCRouteCalculator1GetGeocoding(Sender: TObject;
  const ARequest: TTMSFNCGeocodingRequest;
  const ARequestResult: TTMSFNCCloudBaseRequestResult);
begin
  if ARequest.Items.Count = 0 then
    TTMSFNCUtils.Log(ARequest.ID + ' is invalid')
  else
    TTMSFNCUtils.Log(ARequest.ID + ' is valid');
end;

many tanks .. it works