将文件嵌入到delphi exe应用程序中(而不是与应用程序分开的文件) [英] embedded file into delphi exe application (not as a separate file from the appliaction)

查看:129
本文介绍了将文件嵌入到delphi exe应用程序中(而不是与应用程序分开的文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文件(任何类型的文件)嵌入到我的exe应用程序中,并能够提取到远程文件中以使用它,我知道如何将其嵌入资源中,但是我不想放置文件在app目录中的文件中,我想将所有文件(例如.rec)存储到我的exe中,在c#中,可以将其存储为文本文件,然后通过FileStream读取它,但是在Delphi中,资源文件与exe文件是分开的。
有什么解决方案吗?非常感谢!

i want to embedded a file (any kind of type) to my exe application and be able to extract in the remote to use it, i know how do it by embedded into resource,but i don't want to place the files in the app directory, i want to store all files (like .rec) into my exe, in c# it is possible to store as text file and then read it by FileStream but in Delphi the resource files is separate from the exe file. is there any solution to do this ? Thanks a lot!

推荐答案

您应该制作一个.rc文件并将其添加到您的项目中。 RC文件的内容如下:

You should make an .rc file and add that to your project. The content of the RC file is like:

FIXED48                 IMAGE           ..\Resources\Fixed48x48.png
MENU16                  IMAGE           ..\Resources\Menu16x16.png
TICK            SOUND       ..\Resources\Tick.wav
PING            SOUND       ..\Resources\Ping.wav

现在,执行构建后,您可以使用TResourceStream加载以下其中一个杂项:

Now after you do a build you can load one of these fikles using a TResourceStream:

procedure TdmReportGeneral.InsertLogo(Memo: TStringList; View: TfrView);
var
    S:    TResourceStream;
begin
    if (View is TfrPictureView) and (View.Name = 'Logo') then begin
        S := TResourceStream.Create( 0, 'FIXED48', 'IMAGE' );
        try
            // do something useful... TfrPictureView(View).Picture.MetaFile.LoadFromStream( S );
        finally
            S.Free();
        end;
    end;
end;

这篇关于将文件嵌入到delphi exe应用程序中(而不是与应用程序分开的文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆