乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 58|回复: 3

为什么这个工具面板代码会导致致命错误

[复制链接]

3

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
21
发表于 2015-6-26 06:16:38 | 显示全部楼层 |阅读模式
嗨,
当我运行下面的代码时,我得到一个致命的错误:未处理的访问冲突读取0x0000异常在7f37d9c9h。 任何想法为什么以及如何解决?
  1. Imports Autodesk.AutoCAD.Runtime
  2. Imports Autodesk.AutoCAD.ApplicationServices
  3. Imports Autodesk.AutoCAD.EditorInput
  4. Imports Autodesk.AutoCAD.Windows.ToolPalette
  5. Imports System.Runtime
  6. Public Class RPSPalette
  7.     Friend Shared rpsToolps As Autodesk.AutoCAD.Windows.PaletteSet = Nothing
  8.      _
  9.     Public Sub rpsToolPalette()
  10.         Try
  11.             If rpsToolps Is Nothing Then
  12.                 Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  13.                 Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  14.                 Dim toolPaletteGroupName As String = "RPSToolGroup"
  15.                 Dim rpsToolps As New Autodesk.AutoCAD.Windows.PaletteSet(toolPaletteGroupName)
  16.                 Dim aboutPalette As usrControlAbout = New usrControlAbout()
  17.                 rpsToolps.Add("Abobut Palette", aboutPalette)
  18.             End If
  19.             rpsToolps.Visible = True
  20.         Catch ex As Exception
  21.             Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error!" & vbLf & ex.Message)
  22.         End Try
  23.     End Sub
  24. End Class

AutoCAD2014/Windows7

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

3

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
21
发表于 2015-6-26 06:28:36 | 显示全部楼层
Doh,
  1.             If rpsToolps Is Nothing Then
  2.                 Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  3.                 Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  4.                 Dim toolPaletteGroupName As String = "RPSToolGroup"
  5.                 Dim rpsToolps As New Autodesk.AutoCAD.Windows.PaletteSet(toolPaletteGroupName)
  6.                 Dim aboutPalette As usrControlAbout = New usrControlAbout()
  7.                 rpsToolps.Add("Abobut Palette", aboutPalette)
  8.                 rpsToolps.Visible = True
  9.             End If

是答案。
回复

使用道具 举报

4

主题

219

帖子

4

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
238
发表于 2015-6-26 09:29:09 | 显示全部楼层
我不认为你对第一篇文章的回答是正确的,至少在syntex方面。
此问题可能是因为使用VB.NET时没有设置“Option Strict”标志:您在类级别“rpsToolps”声明了一个“Shared”变量为Nothing,然后在If...然后...您声明了另一个局部变量,也命名为“rptToolps”(如果您使用C#,这是不允许的,然后您会立即注意到您的错误),这就是为什么您自己的答案是移动“rpsToolps”。Visible=True "...然后...声明,它似乎工作。您的“解决方案”的净效果是,您永远不会有指向PaletteSet实例的共享类级引用,并且每次运行您的命令时,都会创建PaletteSet的一个新实例。由于当用户单击“x”关闭PaletteSet时,实际上并不处理它,而只是将其设置为不可见,多次运行您的命令将创建PaletteSet的许多实例,所有以前打开的PaletteSet都作为不可见的无用垃圾驻留在内存中,因此您在AutoCAD进程中创建了“内存泄漏”的情况。
正确的方法是更改(在If...然后...结束If)
将rpsToolps作为新的Autodesk。AutoCAD . windows . paletteset(toolPaletteGroupName)
to
rpsToolps = New Autodesk。AutoCAD . windows . paletteset(toolpalettegroup name)
并离开
rpsToolps。Visible = True
在If外部...然后...就像你最初做的那样。
回复

使用道具 举报

3

主题

9

帖子

1

银币

初来乍到

Rank: 1

铜币
21
发表于 2015-6-26 11:55:35 | 显示全部楼层
感谢您指出我的方法错误。我实际上只是想知道为什么我仍然可以多次出现调色板。现在启用了选项严格。
我实际上正在将相当多的量从VBA转换为. net。作为AutoCAD中的兼职“黑客”和全职土地测量员,您认为尝试使用C#是否明智?
再次感谢,像往常一样,我学到了一些很好的东西。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 00:44 , Processed in 0.411147 second(s), 71 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表