现在很多使用资源文件(*.res)的介绍都是将资源文件在编译时直接编译进程序中,如果资源文件很多,那不是程序文件会相当大?而且编译进程序的资源文件不能再更改,如要更改只能再次编译程序.有没有办法让生成的资源文件独立存在,在程序动行时动态载入并读取,而不编译到exe或dll文件中?

解决方案 »

  1.   

    先编写 一个 资源 dll, myres.dpr,如下:library myres;{ 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. }
    {$R 'myres.res' 'myres.rc'}
    uses
      SysUtils,
      Classes;begin
    end.
    然后创建 vmyres.rc,如下:aaa BITMAP aaa.bmp
    bbb BITMAP bbb.bmp
    ccc BITMAP ccc.bmp然后编译 myres.dpr,生成 myres.dll。下面是使用 vmyres.dll:1,加载资源dll:g_ResHandle := LoadLibrary('myres.dll');2, 使用:bmpa, bmpb, bmpc : TBitmap;bmpa.LoadFromResourceName(g_ResHandle, 'aaa');
    bmpb.LoadFromResourceName(g_ResHandle, 'bbb');
    bmpc.LoadFromResourceName(g_ResHandle, 'ccc');
      

  2.   

    先谢谢Adayuer的热心帮助.
    不过编译到DLL中的办法我知道, 现在我的想法是想用程序直接读取*.res中的资源.
    不要将资源编译到exe或者dll中.
      

  3.   

    不用编译到exe文件里面,干嘛弄成资源文件呢?
    如果你想把很多文件做成一个文件供你的程序调用,那自己定义文件格式就成了;
    自己定义麻烦的话还可以用各种各样的桌面数据库,总之办法太多了,都比资源文件好
      

  4.   

    同意楼上,竟然都不用包含进EXE里,还不如用单机数据库或是直接把资料压缩起来,直接读压缩文件