关于错误Access Violation和too many consecutive exceptions,解决方法

      今天外面又是暴雨如注啊,不知道会不会发洪水,呵呵。外面倾盆大雨的时候,坐在椅子上的我汗水似倾盆大雨。

      昨天刚做完软件更新模块,后来客户需要把现在的程序做成MDI(又是费神的事情)。做就做吧,程序改完,F9。还好没有任何问题(心里正美的),关闭时问题出现了 “.....too many consecutive exceptions...”,我当时差点摔倒,我难道把没有BUG的程序改成有BUG了?看来看去没有任何的问题,代码也是一样。没办法,一条条看吧,哟,找到了一个全局的TList在重复赋值时没有先Free掉。既然问题找到了那就Free吧,运行后,又出现了新的问题,那就是“Access Violation”。我完蛋了,真没办法了。

     最后一招,把BACUPK的文件恢复(常BACKUP项目是很好的习惯),看看是否有问题。一运行不知道,“.....too many consecutive exceptions...”,竟然也出现了,看来里面还是有虫子啊,没办法翻箱倒柜的找这方面的资料。一天的时间就这样一点点流掉了,终于在一篇文章中提到“如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上ShareMem”。DLL项目加ShareMem这个我知道,但主程序中也要加?这我就不明白了,为什么以前不加的时候没这个问题呢?加就加吧,果然加上后一点问题都没有。唉,真是搞不明白。最后在新建DLL项目时,DELPHI有一段注释给了我答案。

  Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source)
USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters.


看到那个project了吗?呵呵,问题就在这儿啦,别说D7有多少的BUG,大多数的时候D7已经给了我们提示,自己没有在意罢了。希望有这样问题的朋友可以一解燃眉之急。
原文地址:https://www.cnblogs.com/sonicit/p/799077.html