Embedded file in delphi exe application (not as a separate file from application)

I want to embed a file (of any type) in my exe application and be able to retrieve it remotely, I know how to do it, built into the resource, but I don’t want to place the files in the application directory, I want to store all the files (for example , .rec) in my exe, in C # you can store it as a text file and then read FileStream, but in Delphi resource files are separated from the exe file. is there any solution for this? Many thanks!

+4
source share
3 answers

You must make a .rc file and add it to your project. The contents of the RC file are as follows:

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

Now after the build, you can load one of these features using 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; 
+16
source

You should be able to force the Delphi compiler to link your resource to your EXE by adding it as a {$ R myresource.res} pragma to your project unit. You can then access it through a FindResource call when you need to read it.

In this article you will find the appropriate steps.

+2
source

DelphiDabbler has an excellent article on this topic. They even include 2 sample download projects that show how to embed a file as a resource and how to read it.

You can download a processed example that demonstrates what we have described here - it uses the above code. The mail file contains a couple of projects. The first is a program that has a rich text file in a resource file. The second program includes a resource file and displays rich text in the above.

+1
source

Source: https://habr.com/ru/post/1301852/


All Articles