views:

262

answers:

5

I need to make an app that will let users select some options, click a button, and a separate compiled app is created. Is this possible? I am using delphi 7 and 2010.

Thanks for the replies. Here is a little more info.

It would have to be a graphical app and create a graphical app.

What I want is the user to fire up 'App A' (I originally made), be able to select some options (I apologize for the secrecy. I think this is a million dollar idea that probably 3 people may find useful :) then use the program to create 'App B.' 'App B' can then be distributed to end users and 'App B' is a single executable that includes a compiled app plus the configuration data. I don't care how, but I need 'App B' to be a single executable.

I wouldn't even need to use Delphi for the final compiled app. If there is some sort of "pseudo-compiler" that I can call from Delphi that would marry a precompiled exe and a separate config file into a single executable. That would work just fine as well.

Thank you for the replies and help.

Thank you.

+1  A: 

It is possible. You will need a Delphi 7 (or compatible) compiler (command line at least) on the target machine. You will also need all the source code for the compiled application and that includes all the third party libraries if you use any.

When you have it all set just call the command line compiler (DCC32.EXE) with the proper parameters and paths.

You can use two approaches for this:

  • Call ShellExecute
  • Call CreateProcess

You will have more control over the execution with CreateProcess. Also you will have to watch out for legal issues and licences if you plan to use the compiler this way.

Runner
+6  A: 

I also faced a similar situation once. I had to produce an exe using my exe. I didn't want to go the compiling a source code because of complexity and license problems.

Lets call the parent app P and child app C. Also lets assume that whatever option C needs can be summed up in a config file (XML/INI etc). What I ended-up doing was:

  1. Create P and C. Inserted C in resource data of P.
  2. When user clicked the button after selecting options, P would extract C from its resource data.
  3. Created an XML file containing the options selected by user and inserted it in C's resource data.

So whenever C will run, it will use the options given in the XML file stuffed in it. It looks like complicated and hacky but is reliable and simple. Do a google on "delphi embedding resource in exe" and you will find plenty of articles to do above.

Hemant
Good choice if you can cover all the options. Probably viable in most situations. Not what he aksed for, but a good advice and a good alternative.
Runner
@Runner, David didn't say he needed to be able to compile source code. He said he needed to produce a compiled app. If he *starts with* a compiled app, copies it, and modifies its resource section, then he will end up with another compiled app, exactly what he asked for. I doubt David meant for others to infer that the program needs to be compiled on-site with the user, especially when he didn't mention any kind of code generation and the only user input is to "select some options."
Rob Kennedy
Right. What I want is the user to fire up 'App A', be able to select some options (I apologize for the secrecy. I think this is a million dollar idea that probably 3 people may find useful :) then use the program to create 'App B.' 'App B' can then be distributed to end users and 'App B' is a single executable that includes a compiled app plus the configuration data. I don't care how, but I need 'App B' to be a single executable.Thank you for the replies and help.
David
@Rob , I see you are correct. English is not my primary language so I missed that. Still I should read better :)
Runner
@David, have a look at the [`UpdateResource`](http://msdn.microsoft.com/en-us/library/ms648049.aspx) API function.
Rob Kennedy
+2  A: 

Given that the Delphi compiler can't be redistributed, one solution if the user has not a copy of Delphi may be to use a script engine (i.e. RemObjects PascalScript, but there are others), generate code for it, and embed that code (i.e. within a resource) in an executable that will execute it when launched.

ldsandon
And PaxCompiler can actually compile executables and even packages, it's worth checking out.
Daniel Maurić
A: 

Without knowing more about why you think you need to do this, I assume you don't actually need to do this. Given the stated requirements, I'd simply have one app, written in Delphi, that looks for the existence of configuration data (.ini file, registry, etc..) In the absence of this, it presents a screen that "will let users select some options, click a button". Then the options are stored in a .ini file, and the rest of the program proceeds, making use of those options.

Alternately, I'd use some pascal scripting, such as provided by TMS.

If you are looking for a way to crank out custom-branded versions of an app, maybe use Inno Setup with a ResHacker step. i.e. gather requirements in Inno, spit out your .exe into a temp directory, use ResHacker to modify the .exe, copy it into the program folder.

Chris Thornton
I may not have to create the second executable, but I need that configuration file to be included in the executable some way.Thank you for the reply.
David
@David, then ResHacker may do the trick for you. i.e. inject the configuration into the .exe as resource strings.
Chris Thornton
Does it really have to be embedded or could you use an encrypted configuration file to prevent meddling?
Mattl
+1  A: 

Create a separate stub executable that implements all the logic you need, and that reads its configuration from its own local resources (look at the TResourceStream class to help you load a resource at runtime).

Include that stub executable as an RCDATA resource in your main app's resources when it is compiled.

At runtime, the main app can extract the stub executable from its resources when needed, save it to disk, and insert the necessary configuration data into the stub's resources using the Win32 API UpdateResource() function.

Remy Lebeau - TeamB