LazMapViewer: Fix crash in demo when "go to point" is selected after loading a saved track.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8183 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-12-30 23:22:49 +00:00
parent ca31a5f9db
commit 7c3d69fa44

View File

@ -2,6 +2,8 @@ unit gpslistform;
{$mode objfpc}{$H+}
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
interface
uses
@ -232,15 +234,18 @@ begin
if OpenDialog.FileName <> '' then
OpenDialog.InitialDir := ExtractFileDir(OpenDialog.FileName);
if not OpenDialog.Execute then exit;
// Create a gpsTrack, read the track points, and add the track to the viewer.
gpsTrack := TGpsTrack.Create;
L := TStringList.Create;
try
L.LoadFromFile(OpenDialog.FileName);
for i := 1 to L.Count - 1 do begin // i=1 --> skip header line
for i := 1 to L.Count - 1 do // i=1 --> skip header line
begin
if L[i] = '' then Continue;
sa := L[i].Split(#9);
if TryStrToGps(sa[2], lon) and TryStrToGps(sa[3], lat) then begin
if TryStrToGps(sa[2], lon) and TryStrToGps(sa[3], lat) then
begin
gpsPt := TGpsPoint.Create(lon, lat);
gpsPt.Name := sa[1];
gpsTrack.Points.Add(gpsPt);
@ -251,11 +256,22 @@ begin
finally
L.Free;
end;
// The track points are needed internally in the FList --> copy the track points
FList.Free;
FList := TGPSObjList.Create(false);
for i := 0 to gpsTrack.Points.Count - 1do
begin
gpsPt := gpsTrack.Points[i];
FList.Add(gpsPt);
end;
// Display the track points in the ListView
ListView.Items.BeginUpdate;
try
ListView.Items.Clear;
for i:=0 to gpsTrack.Points.Count - 1 do begin
for i:=0 to gpsTrack.Points.Count - 1 do
begin
gpsPt := gpsTrack.Points[i];
item := ListView.Items.Add;
item.SubItems.Add(gpsPt.Name);
@ -265,6 +281,7 @@ begin
finally
ListView.Items.EndUpdate;
end;
end;
procedure TGPSListViewer.SetViewer(AValue: TMapView);