map是键值对,类似于C#里的HashTable.在看财务过账的代码时,发现了一段使用Map比较典型的代码,摘录在这里,免得以后找起来麻烦.
代码路径如下:AO->Classes->SalesFormLetter->updateQueryBuild
Map mapSalesRecord;
MapEnumerator mapSalesRecordEnumerator;
;
mapSalesRecord = map::create(Formletter::getFormRecord(callerFormDataSource));
mapSalesRecordEnumerator = mapSalesRecord.getEnumerator();
while (mapSalesRecordEnumerator.moveNext())
{
localSalesTable = mapSalesRecordEnumerator.currentValue();
}
创建map时使用了map类的静态方法create,其入参为container.MapEnumerator mapSalesRecordEnumerator;
;
mapSalesRecord = map::create(Formletter::getFormRecord(callerFormDataSource));
mapSalesRecordEnumerator = mapSalesRecord.getEnumerator();
while (mapSalesRecordEnumerator.moveNext())
{
localSalesTable = mapSalesRecordEnumerator.currentValue();
}
看一下FormLetter的静态方法getFormRecord.
client static container getFormRecord(FormDataSource TradeRecord_ds)
{
common TradeRecord;
Map mapTradeRecord = new map(TYPES::INTEGER,TYPES::RECORD);
for (TradeRecord = TradeRecord_ds.getFirst(true) ? TradeRecord_ds.getFirst(true) : TradeRecord_ds.cursor(); TradeRecord; TradeRecord = TradeRecord_ds.getNext())
{
mapTradeRecord.insert(TradeRecord.RecId,TradeRecord);
}
return mapTradeRecord.pack();
}
{
common TradeRecord;
Map mapTradeRecord = new map(TYPES::INTEGER,TYPES::RECORD);
for (TradeRecord = TradeRecord_ds.getFirst(true) ? TradeRecord_ds.getFirst(true) : TradeRecord_ds.cursor(); TradeRecord; TradeRecord = TradeRecord_ds.getNext())
{
mapTradeRecord.insert(TradeRecord.RecId,TradeRecord);
}
return mapTradeRecord.pack();
}
虽然感觉上面的代码有些过烦,不过做为map的使用示例还是比较适合的.当然也可以用MapIterator类来遍历map,在while()里的将是mapIterator.more(),取值用mapIterator.value,move到下一条用mapIterator.next(),如下所示:
MapIterator mapIterator;
;
mapIterator = new MapIterator(mapSalesRecord);
while(mapIterator.more())
{
localSalesTable = mapIterator.value();
mapIterator.next();
}
;
mapIterator = new MapIterator(mapSalesRecord);
while(mapIterator.more())
{
localSalesTable = mapIterator.value();
mapIterator.next();
}