循环往mapx上写字,画线,但循环五六十次的话程序就变的很慢?求大家帮助 ( 积分: 100 )

  • 主题发起人 主题发起人 pyg666
  • 开始时间 开始时间
P

pyg666

Unregistered / Unconfirmed
GUEST, unregistred user!
var
p: CMapXPoint;
TextFeature: variant;
temp_Point: variant;
begin

for i:=0 to m
begin

pts := CreateOleObject('MapX.Points.4');
XPoint := FXPoint + 1;
YPoint := FYpoint + i * 1;
pts.AddXY(XPoint, YPoint);
XPoint := 5 * 1 + FZhuangHNum * FZhUnit / 100;
pts.AddXY(XPoint, YPoint);

newObj := Map1.FeatureFactory.CreateLine(pts, EmptyParam);

newObj.Style.LineWidth := 1;
//newObj.Style.LineColor := clred;
newObj.Style.LineStyle := 1;
Map1.Layers.Item('Xie').AddFeature(newObj, EmptyParam);




temp_Point := CreateOleObject('MapX.Style.4');
temp_Point.TextFontColor := TextColor;
temp_Point.TextFont.Name := '宋体';
temp_Point.TextFont.Size := Size;
temp_Point.TextFont.Bold := true;
p := CoPoint.Create;
// miPositionCC
p.Set_(x, y);
TextFeature := Map1.FeatureFactory.CreateText(p, Text, aType, temp_Point);
TextFeature.Style.TextFontRotation := Angel;
Map1.Layers.Item('text').AddFeature(TextFeature, EmptyParam)

end;

如果m变大的话程序就变的很慢,
 
var
p: CMapXPoint;
TextFeature: variant;
temp_Point: variant;
begin

for i:=0 to m
begin

pts := CreateOleObject('MapX.Points.4');
XPoint := FXPoint + 1;
YPoint := FYpoint + i * 1;
pts.AddXY(XPoint, YPoint);
XPoint := 5 * 1 + FZhuangHNum * FZhUnit / 100;
pts.AddXY(XPoint, YPoint);

newObj := Map1.FeatureFactory.CreateLine(pts, EmptyParam);

newObj.Style.LineWidth := 1;
//newObj.Style.LineColor := clred;
newObj.Style.LineStyle := 1;
Map1.Layers.Item('Xie').AddFeature(newObj, EmptyParam);




temp_Point := CreateOleObject('MapX.Style.4');
temp_Point.TextFontColor := TextColor;
temp_Point.TextFont.Name := '宋体';
temp_Point.TextFont.Size := Size;
temp_Point.TextFont.Bold := true;
p := CoPoint.Create;
// miPositionCC
p.Set_(x, y);
TextFeature := Map1.FeatureFactory.CreateText(p, Text, aType, temp_Point);
TextFeature.Style.TextFontRotation := Angel;
Map1.Layers.Item('text').AddFeature(TextFeature, EmptyParam)

end;

如果m变大的话程序就变的很慢,
 
1. 程序的设计错误, 多次的CreateOleObject会消耗大量的系统资源(内存,CPU);
2. 修改建议: 在For循环外(for循环开始前)创建pts和temp_Point, 在For循环中
使用pts和temp_Point的时候,先清零;
 
我已经那样做过了,还是慢
 
我就是从MapX中读出对象,M>2000也会有点慢的,何况是写
 
后退
顶部