www.mxdraw.com
内容索引主面
前一个向上下一个
IMxDrawDictionary 接口

数据库中的字典类,用户的自定义数据可以存放在字典中,它可以理解一个映射表,字符串是关键字,可以映射到任何一个对象。字典中可以再包含字典

IDL
[ object, uuid(9D534308-91B2-4F11-8585-E3664B808850), dual, nonextensible, helpstring("IMxDrawDictionary interface"), pointer_default(unique) ]
interface IMxDrawDictionary : IMxDrawMcDbObject;

MxDrawDictionary.idl

例如: VB 向数据库读写用户自定义的全局数据,通过扩展记录实体,代码如下:

写全局数据
            Private Sub writenamedict_Click()
            Dim database As MxDrawXLib.MxDrawDatabase

            Set database = MxDrawX1.GetDatabase

            Dim nameDict  As MxDrawXLib.MxDrawDictionary

            Set nameDict = database.GetNamedObjectsDictionary

            Dim myDict  As MxDrawXLib.MxDrawDictionary

            Set myDict = nameDict.AddObject("MyDict", "McDbDictionary")

            Dim xRecord As MxDrawXLib.MxDrawXRecord
            Set xRecord = myDict.AddXRecord("MyGlobalData")


            If (xRecord Is Nothing) Then
                    MsgBox "向字典中,增加扩展记录失败"
                    Exit Sub
            End If


            Dim xData2 As MxDrawXLib.MxDrawResbuf
            Set xData2 = New MxDrawXLib.MxDrawResbuf



                xData2.AddLong 99999
                xData2.AddDouble 666

                Set ptTest = New MxDrawXLib.MxDrawPoint
                ptTest.x = 77
                ptTest.y = -100

                xData2.AddPoint ptTest

                xData2.AddString "TestApp2", 1001
                xData2.AddString "张三2"

                xRecord.SetXRecordData2 xData2

                 MsgBox "写全局数据成功"


            End Sub
            取全上面写的全局数据
            Private Sub readnamedict_Click()

            Dim database As MxDrawXLib.MxDrawDatabase

            Set database = MxDrawX1.GetDatabase

            Dim nameDict  As MxDrawXLib.MxDrawDictionary

            Set nameDict = database.GetNamedObjectsDictionary

            Dim myDict As MxDrawXLib.MxDrawDictionary
            Set myDict = nameDict.GetAt("MyDict")
            If (myDict Is Nothing) Then
                    MsgBox "字典中,没有自定义数据"
                    Exit Sub
            End If


            Dim xRecord As MxDrawXLib.MxDrawXRecord
            Set xRecord = myDict.GetAt("MyGlobalData")


            If (xRecord Is Nothing) Then
                    MsgBox "向字典中,没有扩展记录"
                    Exit Sub
            End If


            Dim data As MxDrawXLib.MxDrawResbuf

            Set data = xRecord.GetXRecordData2

            data.PrintData


            End Sub

 

例如: C# 向数据库读写用户自定义的全局数据,通过扩展记录实体,代码如下:

        void wirteVer(String sName, String sVal)
        {

            MxDrawDatabase database = (MxDrawDatabase)axMxDrawX1.GetDatabase();
            MxDrawDictionary dict = database.GetNamedObjectsDictionary();

            MxDrawDictionary myDict = (MxDrawDictionary)dict.GetAt("MyExDataDictName");
            if (myDict == null)
            {
                myDict = (MxDrawDictionary)dict.AddObject("MyExDataDictName", "McDbDictionary");

            }

            MxDrawXRecord rec = (MxDrawXRecord)myDict.GetAt(sName);

            if (rec == null)
            {

                rec = myDict.AddXRecord(sName);
            }

            MxDrawResbuf res = new MxDrawResbuf();
            res.AddString(sVal);

            rec.SetXRecordData(res);

        }


        String readVar(String sName)
        {

            MxDrawDatabase database = (MxDrawDatabase)axMxDrawX1.GetDatabase();
            MxDrawDictionary dict = database.GetNamedObjectsDictionary();

            MxDrawDictionary myDict = (MxDrawDictionary)dict.GetAt("MyExDataDictName");
            if (myDict == null)
            {
                return "";

            }

            MxDrawXRecord rec = (MxDrawXRecord)myDict.GetAt(sName);

            if (rec == null)
            {

                return "";
            }

            MxDrawResbuf  ret =  rec.GetXRecordData();

            if (ret == null)
                return "";

            return ret.AtString(0);

        }
        private void buttondict_Click(object sender, EventArgs e)
        {
     

            wirteVer("MyName", "666666");
        }

        private void buttonreaddict_Click(object sender, EventArgs e)
        {
            String sRet = readVar("MyName");
            if (sRet == "")
            {
                MessageBox.Show("没有数据");
            }
            else
            {

                MessageBox.Show(sRet);
            }
        }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!