How to embed exe in Project Delphi?

Asked

Viewed 1,321 times

4

Setting:

I have a system developed in Delphi 5 and another in Delphi EX8.
In Delphi 5 I call the EX8 executable, so far so good, because it would only be an extra program for the user to download and leave in 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.

There is a solution that would bring them together?

Note:

I can’t migrate Project Delphi 5 to EX8.


  • 1

    Just to make sure I understand perfectly, you want to use the program made in Delphi 5 as a resource to be called by the program made in Delphi XE8?

  • I did not see much sense, but you can include as a resource. It is not advisable in this case, but may include. In Delphi 7 had a compilation instruction. I think it was {$R 'filename'}, just as Delphi already included DFM’s in the resource (there is a command of this in each form).

  • @Darkhyudra otherwise, I want to embed an EX8 in a 5

  • 1

    The hole is very deep, and there is a code that a little gringo guy did once, but I can’t promise you that it works in Delphi 5. In this question of the OS, in the first answer has the link to Unit used and more details of how to use it: http://stackoverflow.com/questions/6395493/execute-an-exe-file-from-resource-into-memory

1 answer

3


There is, the procedure is simple to do!

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

Let’s create a test!

  • 1 - Create and save a project with only 1 button in the form.
  • 2 - In the folder where the project sources were saved, copy to the same the file BRCC32.EXE that this in Delphi installation bin folder (I always prefer to copy).
  • 3 - Add an executable file of your choice in this folder!
    • 3.1 - Create a text file (any name) with the following structure (without the explanatory header) in the saved project folder formerly. Resource Name - Identifier - File Path to be attached Arquivoteste Exes "full project folder path file and its extension" (3 vestments, the last one should be in quotes doubles)
    • 3.2 - Change the extension on this file .txt for .rc
  • 4 - We have everything ready to create our resource archive!
    • 4.1 - On Windows Run: 'Folder Path' brcc32' 'filename created in 3.1 with extension' (do not use quotes ex: c:\temp\teste\brcc32 nome_desejado.rc)
    • 4.2 - Note that in the project folder a new file with the same name was created .rc with the extent .res
  • 5 - Open the project and below {$R *.DFM} add {$R name of res files with extension}
  • 6 - In the event click 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 it all worked out, 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, not needing to do the extraction! This script I just put together, if there is something wrong or procedure that failed let me know that I make the correction!

  • +1, what cake recipe huh ? I will test your solution!

  • kkkkk I prefer to answer like this! There are things I don’t like to leave margins for doubt!

  • That’s right, it worked out here thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.