Any ideas how to fill array of record with distance and time?

Hi,

I have a Problem with the asynchronous calculation of waypoints. In my program, I have a list of Marker that should be reached on point after another, and I need the Information of Route Length and Time in my List after going through this list. For better understanding, here is a really simplified version of my Problem. In that Code I want the Information of Length and Time to be written in MyRecordArray[1] and MyRecordArray[2]. But I was not able to archive this because of the asynchronous workflow with the Event handler. Would be great if the Callback function of GetDirections could handle something like Tobject to get a proper Response at that point where I need it.

unit uDemo;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
  Vcl.TMSFNCCustomComponent, Vcl.TMSFNCCloudBase, Vcl.TMSFNCDirections, Vcl.TMSFNCMaps, Vcl.TMSFNCTypes, Vcl.TMSFNCUtils, Vcl.TMSFNCGraphics,
  Vcl.TMSFNCGraphicsTypes, Vcl.TMSFNCMapsCommonTypes, Vcl.TMSFNCCustomControl, Vcl.TMSFNCWebBrowser;

type
  TMyRecord = Record
    Index: Integer;
    Distance: Double;
    Time: Double;
    MyLocation: TTMSFNCMapsMarker;
  End;

  TMyRecordArray = Array of TMyRecord;

type
  TForm2 = class(TForm)
    Button1: TButton;
    TMSFNCDirections: TTMSFNCDirections;
    TMSFNCMaps: TTMSFNCMaps;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
  MyRecordArray: TMyRecordArray;
  MyRecord: TMyRecord;
  ActivePoint: TTMSFNCMapsMarker;
begin
  setlength(MyRecordArray, 3);
  MyRecordArray[0].Index := 0;
  MyRecordArray[0].Distance := 0;
  MyRecordArray[0].Time := 0;
  MyRecordArray[0].MyLocation := TMSFNCMaps.AddMarker(53.476761, 9.703380,'Start Point');

  MyRecordArray[1].Index := 1;
  MyRecordArray[1].MyLocation := TMSFNCMaps.AddMarker(52.520008, 13.404954,'Berlin');

  MyRecordArray[2].Index := 2;
  MyRecordArray[2].MyLocation := TMSFNCMaps.AddMarker(48.856613, 2.352222,'Paris');

  ActivePoint := MyRecordArray[0].MyLocation;

  for MyRecord in MyRecordArray do
  begin
    if MyRecord.MyLocation = ActivePoint then
     continue;

    TMSFNCDirections.GetDirections(ActivePoint.Coordinate.ToRec, MyRecord.MyLocation.Coordinate.ToRec);
    ActivePoint := MyRecord.MyLocation;
  end;


end;

end.

Never mind. I used anonymous method for callbackprocedure to get access to the right objects.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.