Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

embedded file into delphi exe application (not as a separate file from the appliaction)

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!

like image 417
sam Avatar asked Dec 01 '22 11:12

sam


2 Answers

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

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;
like image 97
Ritsaert Hornstra Avatar answered Dec 09 '22 15:12

Ritsaert Hornstra


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

This article takes you through the appropriate steps.

like image 32
Trevor Tippins Avatar answered Dec 09 '22 14:12

Trevor Tippins