我在dll中使用String 类型,但是没有引用ShareMem单元,却能正常运行,没有出现类似内存出错的错误。
为什么不会出现错误? 

解决方案 »

  1.   


    哈哈~换一台没有装delphi的机器上去
      

  2.   

      {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.} 
      
      已经说的很清楚了,如果的导出函数中参数或返回值有string类型,那么就需要引用ShareMem
      至于你dll内部使用string类型跟引不引用ShareMem没关系,ShareMem只是解决dll中直接与外界
      发生交互的string变量内存管理问题,比如何时释放啊该不该释放....  
      

  3.   

    下面是FASTMM的FAQ:
    Q: How do I get my DLL and main application to share FastMM so I can safely pass long strings and dynamic arrays between them?
    A: The easiest way is to define ShareMM, ShareMMIfLibrary and AttemptToUseSharedMM in FastMM4.pas and add FastMM4.pas to the top of the uses section of the .dpr for both the main application and the DLL.