C++ Builder中实现MAPX的Feature

昨天试了一天的Feature,现在还存在的问题有:
1)无法将CMapX***Disp 转换成 tagVariant, 例如例子中,创建线及区域时, 无论你写成下面的任何一种,都创建不成功, 
      Map1->Layers->_Item(Variant(1))->CreateRegion(points, EmptyParam);//编译失败
      Map1->Layers->_Item(Variant(1))->CreateRegion(Variant((IUnknown *)points), EmptyParam);//运行创建不成功      
应该写为:
    Map1->Layers->_Item(Variant(1))->CreateRegion(Variant((CMapXPoints*)points), EmptyParam);//运行创建不成功

而只好改用下面的两行代码:
      feature = Map1->FeatureFactory->CreateRegion(EmptyParam, EmptyParam);
      feature->Parts->Add(points);
2)下面的示例中保留了一个错误,就是用 下面的代码创建Feature时,程序退出会抛出异常。现在还没找到解决的方法,也只好改用其它的方法,如 CreateRegion中使用的方法    
        CMapXFeatureDisp line;
      line.Bind(StringToOleStr("MapX.Feature.5"));
      line.Attach(Map1->OleObject);
3)文本显示不能显示在层上(已解决):.
将原来的Variant("文本图元")改为Variant(WideString("文本图元"))就可以了,但如果有中文,则没了后面的四个字节,只显示“文本”。
示例代码:
void __fastcall TfrmFeature::Map1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{ //只向 动画层中加图元
  if((Button != mbLeft) || (placeFeatureId == -1)) return;
  if(Map1->Layers->Count == 0 ){
    log("日志", "没有图层或动画图层, 不能完成添加Feature的工作");
    placeFeatureId = -1;
    return;
  }
  //动作名称
  String strFeature;
  CMapXPointDisp point;
  //生成的图元
  CMapXFeature * feature = NULL;


  point.Bind(StringToOleStr("MapX.Point.5"));
  point = Map1->ConvertCoordP(Variant(X), Variant(Y), miScreenToMap);

  switch (placeFeatureId)
  {
    case 0:{
      CMapXPointDisp p1;
      CMapXPointDisp p2;
      p1.Bind(StringToOleStr("MapX.Point.5"));
      p2.Bind(StringToOleStr("MapX.Point.5"));
      p1.Set_(point.get_X() -1.0, point.get_Y() + 0.2);
      p2.Set_(point.get_X() + 0.4, point.get_Y() -0.4);
      feature = Map1->FeatureFactory->CreateArc(p1, p2, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
      Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
      strFeature = "形似弧的线图元";}
      break;
    case 1:{
      feature = Map1->FeatureFactory->CreateCircularRegion(miCircleTypeMap, point, Variant(30),  EmptyParam, Variant(99), EmptyParam);
      Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
      strFeature = "似圆的区域";}
      break;
    case 2: {
      //这样做, 在退出程序时,会报异常
      CMapXFeatureDisp line;
      line.Bind(StringToOleStr("MapX.Feature.5"));
      line.Attach(Map1->OleObject);
      line.Type = miFeatureTypeLine;
      line.Style = Map1->DefaultStyle;

      CMapXPointsDisp points;
      points.Bind(StringToOleStr("MapX.Points.5"));
      double x =  point.get_X();
      double y =  point.get_Y();
      points.AddXY(x - 1, y - 0.5);
      points.AddXY(x - 0.5, y + 0.5);
      points.AddXY(x, y);
      points.AddXY(x + 0.5, y - 0.5);
      points.AddXY(x + 1, y + 0.5);
      line.Parts->Add(points);

      //feature = Map1->FeatureFactory->CreateLine(EmptyParam, EmptyParam);
      Map1->Layers->_Item(Variant(1))->AddFeature(line, EmptyParam);
      line->Attach(NULL);
      strFeature = "线, 退出会异常,请用添加区域的方法";}
      break;
    case 3: {
      CMapXPointsDisp points;
      points.Bind(StringToOleStr("MapX.Points.5"));
      double x =  point.get_X();
      double y =  point.get_Y();
      points.AddXY(x - 1, y - 0.5);
      points.AddXY(x - 0.2, y + 0.7);
      points.AddXY(x + 0.3, y - 0.1);
      points.AddXY(x + 0.8, y + 0.6);

      feature = Map1->FeatureFactory->CreateRegion(EmptyParam, EmptyParam);
      feature->Parts->Add(points);
      Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
      strFeature = "区域图元";}
      break;
    case 4: {
      feature = Map1->FeatureFactory->CreateSymbol(EmptyParam, EmptyParam);
      feature->set_Point(point);
      Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
      strFeature = "点图元";}
      break;
    case 5: {
      Variant caption = "文本图元abcdefg";
     caption.ChangeType(0x8);
     feature = Map1->FeatureFactory->CreateText(EmptyParam, caption, EmptyParam, EmptyParam);
      feature->set_Point(point);
      Map1->Layers->_Item(Variant(1))->AddFeature(feature, EmptyParam);
      strFeature = "文本图元";}
      break;

    default:
    ;
  }
  placeFeatureId = -1;
  log("日志", strFeature + "位置 x:" + String(point.get_X()) + " y:" + String(point.get_Y()) +( feature == NULL ?" faile":" secc"));




你可能感兴趣的:(C++,工作,String,null,button)