如何通过扩展记录实体向数据库读写用户自定义的全局数据?
VB开发|黄洪辉|2018-06-13 10:50
-
回答:
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