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 pDic.Item("b"); "..."
' // Change key "b" to "m" and "Belgrade" to "México"
pDic.Key("b") = "m"
pDic.Item("m") = "México"
print pDic.Item("m")
' // 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
' // 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
' // 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 "Press any key to finish ..."
SLEEP