程序出现内存溢出(out the memory)(200分)

  • 主题发起人 sxm_alice
  • 开始时间
S

sxm_alice

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure tform1.match(s:string);
var
ft,ftr1,ft1:cmapxfeature;
// ft是建立的缓冲圆, ftr1是街道中心线, ft1相交图元
fs:cmapxfeatures;
// 街道中心线的所有图元
j,i,cnt:integer;
pt,pt1,pt2:Cmapxpoint;
obj:variant;
// 相交的图元
arrVals: Variant;
// 节点
x,y:array of array of do
uble;
// x,y:中心线的节点,第一维表示节点的序号,第二维表示选择的图元序号;
x1,y1:array of do
uble;
// x1,y1:存储某图元所有节点中最短距离的点
x2,y2:double;
// 所有相交图元中最短距离的点
pts1:cmapxpoints;
// 作垂足的线
dd,tt:double;
// 中间变量
dist,d:double;
// dist:两点之间的距离,d:比较所有图元的最短距离点
begin
if v_temp.Speed<>'0' then
begin
map1.MapUnit:=7;
//匹配道路
if radiu<>0 then
//先圆相交,然后判断点的距离
begin

{ lyr.Search('起点方向>='+v_temp.direction+' and 终点方向<='+v_temp.direction+'',emptyparam);
fs:=lyr.Selection.Clone;}

pt:=copoint.create;
pt.Set_(V_Temp.longitude,V_Temp.latitude);
pt1:=copoint.Create;
pt2:=copoint.Create;

ft:=map1.FeatureFactory.CreateCircularRegion(1,pt,radiu,miUnitMeter,24,map1.DefaultStyle);
//以接收到的点做圆
fs:=map1.Layers.Item['街道中心线'].SearchWithinDistance(pt,radiu+100,miUnitMeter,1);
//接收点200米范围内的街道中心线的所有图元
//////////////画最短路径
tt:=1000000;
if fs.Count=0 then
begin
fs:=map1.Layers.Item['街道道路'].SearchWithinDistance(pt,radiu+100,miUnitMeter,1);
if fs.Count>0 then
begin
setlength(x1,fs.Count);
setlength(y1,fs.Count);
for j:=1 to fs.Count do
begin
ftr1:=fs.Item[j];
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
obj:=map1.FeatureFactory.IntersectFeatures(ft,ftr1);
if ftr1.Type_=0 then
continue
else
if ftr1.Type_=1 then
begin
//obj:=ftr1;
arrVals:=obj.Nodes;
cnt:=arrVals[1,1];
setlength(x,cnt,fs.Count);
setlength(y,cnt,fs.Count);
dd:=1000000;
for i:=1 to cnt do
begin
x[i-1,j-1]:=arrVals[2*i,1];
y[i-1,j-1]:=arrVals[2*i+1,1];
dist:=map1.Distance(x[i-1,j-1],y[i-1,j-1],pt.X,pt.Y);//接收点与中心线节点的距离
//求最短路径的点
if dist<dd then
begin
x1[j-1]:=x[i-1,j-1];
y1[j-1]:=y[i-1,j-1];
dd:=dist;
end;
end;
end;
end;
//endif
d:=map1.Distance(x1[j-1],y1[j-1],pt.X,pt.Y);
if d<tt then
begin
x2:=x1[j-1];
y2:=y1[j-1];
tt:=d;
end;
end;
//endfor j
end;
end
else
if fs.Count>0 then
begin
setlength(x1,fs.Count);
setlength(y1,fs.Count);
for j:=1 to fs.Count do
begin
ftr1:=fs.Item[j];
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
ft1:=map1.FeatureFactory.IntersectFeatures(ftr1,ft);
obj:=ft1;
if ft1.Type_=2 then
//miFeatureTypesymbol then
begin
x1[j-1]:=obj.centerx;
y1[j-1]:=obj.centery;
end
else
// if ft1.Type_=1 then
//miFeatureTypeLine then
begin
arrVals:=obj.Nodes;
cnt:=arrVals[1,1];
setlength(x,cnt+1,fs.Count);
setlength(y,cnt+1,fs.Count);
dd:=1000000;
for i:=1 to cnt do
begin
x[i-1,j-1]:=arrVals[2*i,1];
y[i-1,j-1]:=arrVals[2*i+1,1];
dist:=map1.Distance(x[i-1,j-1],y[i-1,j-1],pt.X,pt.Y);//接收点与中心线节点的距离
//求最短路径的点
if dist<dd then
begin
x1[j-1]:=x[i-1,j-1];
y1[j-1]:=y[i-1,j-1];
dd:=dist;
end;
end;
end;

///放入垂足,水平线
pts1:=copoints.Create;
pt1.Set_(v_temp.longitude,v_temp.latitude);
pts1.Add(pt1,emptyparam);
pt1.Set_(v_temp.longitude,v_temp.latitude+0.001);
pts1.Add(pt1,emptyparam);
ft:=map1.FeatureFactory.CreateLine(pts1,map1.DefaultStyle);
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
ft:=map1.FeatureFactory.IntersectFeatures(ftr1,ft);
x[cnt,j-1]:=ft.CenterX;
y[cnt,j-1]:=ft.CenterY;
end
else
begin
pts1:=copoints.Create;
pt1.Set_(v_temp.longitude,v_temp.latitude);
pts1.Add(pt1,emptyparam);
pt1.Set_(v_temp.longitude,v_temp.latitude-0.001);
pts1.Add(pt1,emptyparam);
ft:=map1.FeatureFactory.CreateLine(pts1,map1.DefaultStyle);
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
ft:=map1.FeatureFactory.IntersectFeatures(ftr1,ft);
x[cnt,j-1]:=ft.CenterX;
y[cnt,j-1]:=ft.CenterY;
end
else
begin

///放入垂足,垂直线
pt1.Set_(v_temp.longitude,v_temp.latitude);
pts1.Add(pt1,emptyparam);
pt1.Set_(v_temp.longitude+0.001,v_temp.latitude);
pts1.Add(pt1,emptyparam);
ft:=map1.FeatureFactory.CreateLine(pts1,map1.DefaultStyle);
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
ft:=map1.FeatureFactory.IntersectFeatures(ftr1,ft);
x[cnt,j-1]:=ft.CenterX;
y[cnt,j-1]:=ft.CenterY;
end
else
begin
pt1.Set_(v_temp.longitude,v_temp.latitude);
pts1.Add(pt1,emptyparam);
pt1.Set_(v_temp.longitude-0.001,v_temp.latitude);
pts1.Add(pt1,emptyparam);
ft:=map1.FeatureFactory.CreateLine(pts1,map1.DefaultStyle);
if map1.FeatureFactory.IntersectionTest(ftr1,ft,miintersectfeature) then
begin
ft:=map1.FeatureFactory.IntersectFeatures(ftr1,ft);
x[cnt,j-1]:=ft.CenterX;
y[cnt,j-1]:=ft.CenterY;
end ;
end;
end;
end;
//判断垂足到接收点的距离
dd:=map1.Distance(x1[j-1],y1[j-1],pt.X,pt.Y);
//单一图元所有节点中距离最短的点
dist:=map1.Distance(x[cnt,j-1],y[cnt,j-1],pt.X,pt.Y);//接收点与中心线节点的距离
if dist<dd then
begin
x1[j-1]:=x[cnt,j-1];
y1[j-1]:=y[cnt,j-1];
end;
end;
//endif
d:=map1.Distance(x1[j-1],y1[j-1],pt.X,pt.Y);
if d<tt then
begin
x2:=x1[j-1];
y2:=y1[j-1];
tt:=d;
end;
end;
//endfor j
end;
//end if fs>0
//x2,y2是要求的匹配的点
if int(x2)<>0 then
begin
v_temp.longitude:=x2;
v_temp.latitude:=y2;
//pt.Set_(x2,y2);
end;

varclear(obj);
varclear(arrVals);
ft:=nil;
ftr1:=nil;
ft1:=nil;
pt1:=nil;
pt2:=nil;
pts1:=nil;
fs:=nil;
x:=nil;
y:=nil;
x1:=nil;
y1:=nil;
end;
//endif radiu
end;
end;

上面的代码我如果在别的过程中调用,运行一段时间就会出现out the memory,而且很随机,如果不在其他过程调用不会出现问题,望大家看看哪出现问题了。代码中的radiu是全局变量
 
麻烦版主把此帖子转入delphi技术区
 
太长了.
 
顶部