Add the following to the project. cpp file (project1.cpp:
# Include "unit1.h"
Winapi winmain (hinstance, hinstance, lpstr, INT)
{
Try
{
Application-> initialize ();
Application-> createform (_ classid (tfrmmain), & frmmain );
Application-> Run ();
}
Catch (exception & exception)
{
Application-> showexception (& exception );
}
Catch (...)
{
Try
{
Throw exception ("");
}
Catch (exception & exception)
{
Application-> showexception (& exception );
}
}
If (g_bisrunagain)
{
Ansistring strpath;
Startupinfo startinfo;
Process_information procstruct;
Memset (& startinfo, 0, sizeof (startupinfo ));
Startinfo. cb = sizeof (startupinfo );
Strpath = Application-> exename;
If (! : CreateProcess (
(Lpctstr) strpath. c_str (),
Null,
Null,
Null,
False,
Normal_priority_class,
Null,
Null,
& Startinfo,
& Procstruct ))
Return 0;
}
Return 0;
}
Add the following to the unit header file (unit1.h) in the main window:
Extern bool g_bisrunagain;
In the unit. cpp (unit1.cpp) of the main window, add:
Bool g_bisrunagain = false;
//----------------------------------------------------------------------------
// Close the program
Void _ fastcall tfrmmain: btncloseclick (tobject * sender)
{
Close ();
}
//----------------------------------------------------------------------------
// Restart the application
Void _ fastcall tfrmmain: btnreexcuteclick (tobject * sender)
{
G_bisrunagain = true;
Close ();
}