Several people have inquired about how to have an exemod
application save data on program shutdown without causing
the application to just pop up again.

It is easy to modify an exe each time it starts... but it's a confusing
mess to do the same at each shutdown! :-(

I will be adding a new procedure in version 2 of ExeMod.pas
called AlterAndHalt();  this will work just like AlterExe(); does but
the program will NOT come up running... it will terminate after the
changes have been made to the exe... this code requires changes
to the initialization section of exemod to enable the magic via 
command line parameters... the code is done but debugging
and testing are not...

I have created this demo to show how you can accomplish the
same thing with the current version of exemod.....

Don't ponder this code for long or your head will explode :-)
It is a quirky way to keep the exe from running over and over
... just trust me that it works and simply paste it into your program :-)

The demo has a single button... when you click it it changes it's
caption... once you have changed the caption the program
will store the change into the exe at shutdown.... it will NOT
re-start!  The next time the exe is run it will display the changed
button caption... either 'HELLO' or 'HOWDY' depending on
which caption was stored in the exe at shutdown. This is a way
to replace the utility of an ini file by storing changed data inside
the exe itself....

The demo will NOT attempt to store a change at shutdown
unless the caption has been altered! 

Please note that setting the global boolean variable 'kill' to
true is what causes the program to store a changed version
of itself at termination and then not re-start!

This code passes a message to the new version that comes up
running after an AlterExe has been issued... it passes the message
by saving a tiny data file named kill.dat... kill.dat is always cleaned
up so you will not have it hanging around on disk :-)

If you have any questions about this email me and I will do my
best to help.... this is strange code and it is hard to get a grip
on it..even for me and I wrote it ;-)



var
  Form1: TForm1;
  Kill: Boolean; // HERE IS THE ALL IMPORTANT kill variable!

implementation

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
var Temp: String;
begin
if UpperCase(ExtractFileName(Application.ExeName)) <> ('TEMP0A0.EXE') then
begin
If DeleteFile('kill.dat') then  Application.Terminate; //don't forget this line!

ExtractFromExe('Caption',Temp);                    //this code can be replaced by whatever you need
If Temp <> '' then Button1.Caption := Temp;  //in this demo it just displays the correct caption...   

Exe := ''; //DON'T leave this out or you will create an UNSTOPPABLE exe ;-)
end;
end;

procedure TForm1.FormDestroy(Sender: TObject); //just paste in this code exactly as is!
begin
if UpperCase(ExtractFileName(Application.ExeName)) = ('TEMP0A0.EXE') then Exit;
SetCurrentDir(ExtractFilePath(Application.ExeName));
If kill then String2File(':-)','kill.dat'); //save the file that passes the message
alterexe;
end;

procedure TForm1.Button1Click(Sender: TObject);
var Temp: String;
begin
If Button1.Caption = 'HELLO' then Button1.Caption := 'HOWDY' else
Button1.Caption := 'HELLO';
kill := true; //set up exe to modify when terminated! this is IMPORTANT.. don't forget this line!
InsOrReplaceInExe('Caption', Button1.Caption);
end;

end.
 