MapX SetKeyField及GetKeyValue使用举例。
2007-10-29 22:34
627 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
/**//*
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
MapInfo Products Knowledge Base
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Product: MapX
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Version: 5.x
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Platform: Not Platform Related
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Category: VC++ Code Samples
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Summary:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Extract data from a layer using the keyvalue/keyfield properties.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Question:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
How can the keyvalue/keyfield properties be used to extract data from a layer in C++?
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Answer:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Try this code:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
*/
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//Counters
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
long numFtrs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
long numFlds;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//message buffer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CString Buffer;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CMapXLayer lyr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CMapXFeatures ftrs;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CMapXDataset ds;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//Create a variant for the layer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
VARIANT vLyr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
vLyr.vt = VT_DISPATCH;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//add the layer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
lyr = m_ctrlMapX.GetLayers().Add(LPCTSTR("USA"),1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
vLyr.pdispVal = lyr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//create the dataset
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ds = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vLyr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//init the counters
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
numFtrs = lyr.AllFeatures().GetCount();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
numFlds = ds.GetFields().GetCount();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//build and save the feature set
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//faster than rebuilding the feature every time through the loop
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
ftrs = lyr.AllFeatures();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//loop through the features
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
for (long i = 1; i <= numFtrs; i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//reset the buffer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Buffer = "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//loop through the fields
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for (long j = 1; j <= numFlds; j++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//set the keyfield
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
lyr.SetKeyField(LPCTSTR(ds.GetFields().Item(j).GetName()));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//get the keyvalue for that field add it to the buffer
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Buffer += ftrs.Item(i).GetKeyValue();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//add formating
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Buffer += " ";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//display all the information for the feature
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AfxMessageBox(LPCTSTR(Buffer));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- Memcached expire 设置错误引起的set(key,exp,value)为true而get(key)为null的问题
- 使用SetCurrentRowWithKeyValue
- setValue:forKey与setObject:forKey的差异 在使用NSMutableDictionary的时候经常会使用setValue forKey与setObject forKey,他
- Memcached expire 设置错误引起的set(key,exp,value)为true而get(key)为null的问题
- Memcached expire 设置错误引起的set(key,exp,value)为true而get(key)为null的问题
- 如何使用set::key_comp 和 set::value_comp 标准模板库 (STL) 函数
- setValueForKeyPath理解。访问设置对象的属性的话可以使用setValue forKey 访问属性的属性forKeyPath
- 使用SetCurrentRowWithKeyValue
- iOS- 报错(崩)[< > setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key
- 注解的力量 -----Spring 2.5 JPA hibernate 使用方法的点滴整理(三):通过 @Autowired的使用来消除 set ,get方法。
- 【封装】java中为什么要将属性进行私有化,又使用set和get方法来设置和获取属性呢?
- dto对象包装工具,减少get,set使用,简化代码
- 第二讲实例变量可见度,set/get方法,自定义初始化(代码) 及description的使用
- 使用反射调用set和get方法
- gpio_direction_output vs gpio_set_value之间的使用关系
- 使用@property 改变get和set
- C# 参考之上下文关键字get、set、value、partial、where和yield(zhuan)
- PHP使用方法重载实现动态创建属性的get和set方法
- 问题解决[<UIViewController 0x8430220>setValue:forUndefinedKey:]this class is not key value..
- get_ds, set_fs, get_fs函数的使用