Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TdxAzureMapRouteProviderOnResponse Type

The procedural type for Azure Maps Route server response events.

#Declaration

Delphi
TdxAzureMapRouteProviderOnResponse = procedure(ASender: TdxMapControlAzureMapRouteProvider; AResponse: TdxAzureMapRouteRequestResponse; var ADestroyResponse: Boolean) of object;

#Parameters

Name Type Description
ASender TdxMapControlAzureMapRouteProvider

Provides access to the Azure Maps Route information component that raised the server response event.

AResponse TdxAzureMapRouteRequestResponse

Provides access to a container populated with information returned by a server.

ADestroyResponse Boolean

Specifies if the response event handler automatically destroys the information container accessible through the AResponse parameter. The event handler creates a new server response information container every time the event occurs.

True
Default. The AResponse container is destroyed automatically once the application exits the current event handler. You do not need to manage the response information container manually.
False

Use this option if you need to use the returned information container outside the server response event handler.

Important

Call the Free procedure (in Delphi) or use the delete keyword (in C++Builder) to destroy TdxAzureMapRouteRequestResponse class instances manually if you set the ADestroyResponse parameter to False. Otherwise, memory leaks will occur.

#Remarks

Response events allow you to receive and process a server response after an asynchronous query.

#Code Example: Build a Map Route Asynchronously

The code example in this section demonstrates a procedure that sends a query to an Azure Maps Route server and an OnResponse event handler that receives and processes the server response. The event handler uses an existing map item layer to draw a route between two specified points on a map if the query is successful.

uses
  dxAzureMapInformationProviders,  // Declares TdxMapControlAzureMapRouteProvider
  dxMessageDialog,  // Declares the dxMessageDlg global function
  dxCoreGraphics;  // Declares TdxAlphaColors
// ...

procedure TMyForm.SendRouteQuery(ARouteStart, ARouteEnd: TdxMapControlGeoPoint);
var
  AQueryParams: IdxAzureMapRouteQueryParams;
  ARouteWaypoints: TdxMapControlGeoPoints;
begin
  AQueryParams := dxMapControl1AzureMapRouteProvider1.CreateQueryParams;
  SetLength(ARouteWaypoints, 2);
  ARouteWaypoints[0] := ARouteStart;
  ARouteWaypoints[1] := ARouteEnd;
  AQueryParams.WayPoints := ARouteWaypoints;
  AQueryParams.TravelMode := TdxAzureMapRouteTravelMode.Car;
  AQueryParams.MaxAlternatives := 1;
  dxMapControl1AzureMapRouteProvider1.ExecuteAsync(AQueryParams);
end;

procedure TMyForm.dxMapControl1AzureMapRouteProvider1Response(
  ASender: TdxMapControlAzureMapRouteProvider;
  AResponse: TdxAzureMapRouteRequestResponse; var ADestroyResponse: Boolean);
var
  APolyline: TdxMapPolyline;
  ARoute: TdxAzureMapRouteItem;
  I, J: Integer;
begin
  dxMapControl1.BeginUpdate;  // Initiates the following batch change
  try
    if AResponse <> nil then
    begin
      if AResponse.IsSuccess then  // Draws a route if a valid server response is received
      begin
        APolyline := dxMapControl1ItemLayer1.AddItem(TdxMapPolyline) as TdxMapPolyline;
        ARoute := AResponse.Routes.Items[0];  // Selects the first returned route
        for I := 0 to ARoute.Legs.Count - 1 do
          for J := 0 to ARoute.Legs.Items[I].Points.Count - 1 do
            APolyline.GeoPoints.Add.GeoPoint := ARoute.Legs.Items[I].Points.Items[J];

        APolyline.Style.BorderWidth := 4;
        APolyline.Style.BorderColor := TdxAlphaColors.DarkBlue;
      end
      else if Assigned(AResponse.ErrorInfo) then
        dxMessageDlg(AResponse.ErrorInfo.Message, TMsgDlgType.mtError, [mbOK], 0);
    end;
  finally
    dxMapControl1.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

#Direct TdxAzureMapRouteProviderOnResponse Type Reference

The TdxMapControlAzureMapRouteProvider.OnResponse event references the TdxAzureMapRouteProviderOnResponse procedural type.

See Also