1

With the code below I am trying to reload a DirectionsResult back into a TGMDirections.

procedure Form2.Button2Click(Sender: TObject);
var
  DR: TDirectionsResult;
  i: Integer;
begin
  DR:= TDirectionsResult.Create(Form1.FDirection, 0);
  DR.XMLData.BeginUpdate;
  for i:= 0 to Memo1.Lines.Count - 1 do
  begin
    DR.XMLData.Append(Memo1.Lines[i]);
  end;
  DR.XMLData.EndUpdate;
  ShowMessage(Form1.FDirection.DirectionsResult[0].Routes[0].Leg[0].EndAddress);
end;

All seems well until the ShowMessage where I get a List out of bounds message. I take it that the DR has not been created or the Memo has not loaded into the DirectionsResult.

Further adaption has confirmed the DirectionsResult[0] does not exist.

Help with the correction would be greatly appreciated.

4

1 回答 1

1

您不能以编程方式将 TDirectionsResult 添加到 DirectionsResult 数组,您需要从 TGMDirections 对象调用 Execute 方法。

但是你可以做这样的事情

procedure TForm1.Button1Click(Sender: TObject);
var
  DR: TDirectionsResult;
begin
  DR:= TDirectionsResult.Create(GMDirection1, 1);
  DR.XMLData.Text := Memo1.Lines.Text;
  ShowMessage(DR.Routes[0].Leg[0].EndAddress);
end;

也就是说,您可以毫无问题地使用对象,并且可以访问所有属性和方法。

注意 XMLData 和 Memo.Lines 之间的分配,不要将行分配到行,因为 XML 的控制是在 XMLData 的 OnChange 事件上进行的。

问候。

于 2013-05-14T22:46:41.077 回答