导航:  »没有这个级别以上的主题«

CWstrDic Class

上一页返回章节概述下一页

CWstrDic 是CWSTR的关联数组。 每个项目都与唯一的密钥相关联。 该密钥用于检索单个项目。

 

示例

 

#define unicode

#include once "windows.bi"

#include once "Afx/CWstrDic.inc"

using Afx

 

' // 创建CWstrDic类的实例

DIM pDic AS CWstrDic

 

' // 添加一些关键的值对

pDic.Add "a", "Athens"

pDic.Add "b", "Belgrade"

pDic.Add "c", "Cairo"

 

print "Count: "; pDic.Count

print pDic.Exists("a")

print

 

' // 检索项目并显示

print pDic.Item("b"); "..."

print

 

' // Change key "b" to "m" and "Belgrade" to "México"

pDic.Key("b") = "m"

pDic.Item("m") = "México"

print pDic.Item("m")

print

 

' // Get all the items and display them

DIM cwsaItems AS CWstrArray = pDic.Items

FOR i AS LONG = cwsaItems.LBound TO cwsaItems.UBound

 print cwsaItems.Item(i)

NEXT

 

print

 

' // Get all the keys and display them

DIM cwsaKeys AS CWstrArray = pDic.Keys

FOR i AS LONG = cwsaKeys.LBound TO cwsaKeys.UBound

 print cwsaKeys.Item(i)

NEXT

 

print

 

' // Remove key "m"

pDic.Remove "m"

IF pDic.Exists("m") THEN PRINT "Key m exists" ELSE PRINT "Key m doesn't exists"

 

' // Remove all keys

pDic.RemoveAll

print "All the keys must have been deleted"

print "Count: "; pDic.Count

 

PRINT

PRINT "Press any key to finish ..."

SLEEP