今天又遇到了问题解决不了,创建层!!!

下面的代码失败了,但同等的delphi和Vb是成功的。先放在这,以后解决
bcb代码如下:   
   CMapXLayerInfoDisp layerInfo;
   CMapXFieldsDisp fields;

   layerInfo.Bind(StringToOleStr("MapX.LayerInfo.5"));
   if(!layerInfo.IsBound()){
       ShowMessage("绑定MapX.LayerInfo.5失败!!" );
       return;
   }
   fields.Bind(StringToOleStr("MapX.Fields.5"));
   if(!fields.IsBound()){
       ShowMessage("绑定MapX.Fields.5失败!!" );
       layerInfo.Unbind(true);
       return;
   }
   fields.AddStringField(Variant("ID"), Variant(12), EmptyParam);
   fields.AddStringField(Variant("Name"), Variant(50), EmptyParam);
   fields.AddNumericField(Variant("Deptch"), Variant(12), Variant(2), EmptyParam);
   fields.AddIntegerField(Variant("Length"), EmptyParam);
   layerInfo.Type =  miLayerInfoTypeNewTable;
   layerInfo.AddParameter(WideString("FileSpec"), Variant(WideString("c://test.tab")));
   layerInfo.AddParameter(WideString("NAME"), Variant(WideString("sds")));
   layerInfo.AddParameter(WideString("Fields"), Variant((CMapXFields *)fields));
   CMapXLayer *newLayer = m_map->Layers->Add(Variant((CMapXLayerInfo *)layerInfo), EmptyParam);
   if(newLayer == NULL){
      ShowMessage("创建MapX.Layer失败!!");
      layerInfo.Unbind(true);
      fields.Unbind(true);
      return;
   }
Dephi代码如下(能正常运行)
  Lyr:CMapXLayer;
  LayerInfo:CMapXLayerInfo;
  Flds:CMapXFields;
  FileSpec: String;
begin
 
LayerInfo :=CoLayerInfo.Create();
  Flds := CoFields.Create();
  Flds.AddStringField('ID', 12, EmptyParam);
  Flds.AddStringField( 'Name', 50, EmptyParam);
  Flds.AddNumericField( 'Deptch', 12, 2, EmptyParam);
  Flds.AddIntegerField( 'Length', EmptyParam);

  LayerInfo.Type_ := miLayerInfoTypeNewTable;
  LayerInfo.AddParameter( 'FileSpec', 'c:/test.tab');
  LayerInfo.AddParameter( 'NAME', 'hello');
  LayerInfo.AddParameter( 'Fields', Flds);

  Lyr := Map1.Layers.Add(LayerInfo, EmptyParam);
  if(Lyr = nil) then
  begin
        ShowMessage('错误');
  end;

你可能感兴趣的:(c,String,null,vb,Delphi)