How to embed exe in Delphi Project?

3

Scenario:

I have a system developed in Delphi 5 and another in Delphi EX8. In Delphi 5 I call the EX8 executable, so that's fine, because it would be just another program for the user to download and leave in the bin folder, but I will have to create 2 new modules that will be called in the same way, and this would generate many files to download.

Is there a solution that would unify them?

Note:

  

I can not migrate Project Delphi 5 to EX8.

asked by anonymous 22.01.2016 / 13:22

1 answer

2

There is, the procedure is simple to do!

You will use BRCC32 which is also responsible for generating Delphi Features!

Let's create a test!

  • 1 - Create and save a project with just 1 button on the form.
  • 2 - In the folder where the project sources were saved, copy it to the same the BRCC32.EXE file that is in the Delphi installation Bin folder (I always prefer to copy).
  • 3 - Add to this folder also an executable file of your choice!
    • 3.1 - Create a text file (any name) with the following structure (without the explanatory heading) in the saved project folder previously. Resource Name - Identifier - File Path to be attached File EXEs "full path of project folder \ name of file and its extension "(3 parts, the last one must be in quotation marks double)
    • 3.2 - Change the extension of this file from .txt to .rc
  • 4 - We have everything ready to create our resource file!
    • 4.1 - Do not run windows: 'Folder path' '\ brcc32' 'filename created in 3.1 with extension' (do not use quotes ex: c:\temp\teste\brcc32 nome_desejado.rc )
    • 4.2 - Notice that in the project folder a new file with the same name as .rc was created with the extension .res
  • 5 - Open the project and below {$ R * .DFM} add {$ R name file res with extension}
  • 6 - In the click event of the button we will perform the Extraction of the executable to be used by the system.
procedure frmTeste.btnIniciarClick(Sender: TObject);
var
  Stream: TResourceStream;
begin                                        
  Stream := TResourceStream.Create(hInstance, 'ArquivoTeste', 'EXEs'); //Nome do recurso criado e Tipo 
  try
    Stream.SaveToFile('caminho_completo\ArquivoTeste.exe'); //ex: c:\temp\teste\ArquivoTeste.exe
  finally
    Stream.Free;
  end;
end;
  • 7 - Compile the project to make sure everything is fine, delete the RC files, RES, and the executable that was attached!
    • 7.1 - Run the application and test!

Some features can be used in memory, no need to extract! This script I just set up, if you have something wrong or a procedure that failed, let me know that I will correct it!

    
22.01.2016 / 14:59