henrylim
asked on
Exe Control
In a local database app, I need a way to make the subordinate exe's dependent on the main form in order to implement the database login. Without the main exe running, the sub exe's won't run.
not sure what you mean... sorry..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh i see now... you can use FindExecutable() in order to find the path to your MAN EXE file...
Good Luck!!
..-=ViKtOr=-..
Good Luck!!
..-=ViKtOr=-..
MAN=MAIN
MAN=MAIN <--True in my house anyway ;-)
ASKER
Hi Inth,
I'm pretty new to Delphi programming, could you show me how ?
I'm pretty new to Delphi programming, could you show me how ?
hi,
sure i give example just send me a email to me at legend@enterprise.net and i'll send you back a example of doing this..
Regards Barry
sure i give example just send me a email to me at legend@enterprise.net and i'll send you back a example of doing this..
Regards Barry
nevermind here is examples.
after building these the second unit1 will only run if the first unit1 is already running.
app1 look like this:
unit Unit1;
interface
uses
Windows,Registry, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
Var r: TRegistry;
a: bool;
{ remember to add registry to the uses section ,it is not normally there.}
begin
a:= true; //a is our boolean value we set to true
//because the app is now running
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE; //set the registrys rootkey
with r do
try
CreateKey('Software\NameOf MyProgram' ); //create the registry key
OpenKey('Software\NameOfMy Program', False); //open it
WriteBool('IsRunning',a); //write our value to the registry
{look in delphi help files for many other registry functions,writebinarydata, writestrin g,writeint eger etc}
CloseKey; //close it
finally
free; //free it
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
Var r: TRegistry;
a: bool;
begin
a:= False; //set key to false on form destroy
//now when app 2 looks here it will see app 1 is not running
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE;
with r do
try
CreateKey('Software\NameOf MyProgram' );
OpenKey('Software\NameOfMy Program', False);
WriteBool('IsRunning',a); //commit the change to registry
CloseKey;
finally
free;
end;
end;
end.
app 2 look like this:
unit Unit1;
interface
uses
Windows,Registry, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
Var r: TRegistry;
a: bool;
{ remember to add registry to the uses section ,it is not normally there.}
begin
a:= false;
{set A to false in case key does not exist in registry
in which case app1 has never been run so we
cant run app2 yet.}
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE;
with r do
try
CreateKey('Software\NameOf MyProgram' );
OpenKey('Software\NameOfMy Program', False);
a := ReadBool('IsRunning'); //read the value into A
CloseKey;
finally
free;
end;
if a = False then application.Terminate
end;
end.
Regards Barry
after building these the second unit1 will only run if the first unit1 is already running.
app1 look like this:
unit Unit1;
interface
uses
Windows,Registry, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
Var r: TRegistry;
a: bool;
{ remember to add registry to the uses section ,it is not normally there.}
begin
a:= true; //a is our boolean value we set to true
//because the app is now running
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE; //set the registrys rootkey
with r do
try
CreateKey('Software\NameOf
OpenKey('Software\NameOfMy
WriteBool('IsRunning',a); //write our value to the registry
{look in delphi help files for many other registry functions,writebinarydata,
CloseKey; //close it
finally
free; //free it
end;
end;
procedure TForm1.FormDestroy(Sender:
Var r: TRegistry;
a: bool;
begin
a:= False; //set key to false on form destroy
//now when app 2 looks here it will see app 1 is not running
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE;
with r do
try
CreateKey('Software\NameOf
OpenKey('Software\NameOfMy
WriteBool('IsRunning',a); //commit the change to registry
CloseKey;
finally
free;
end;
end;
end.
app 2 look like this:
unit Unit1;
interface
uses
Windows,Registry, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
Var r: TRegistry;
a: bool;
{ remember to add registry to the uses section ,it is not normally there.}
begin
a:= false;
{set A to false in case key does not exist in registry
in which case app1 has never been run so we
cant run app2 yet.}
r := TRegistry.Create;
r.RootKey := HKEY_LOCAL_MACHINE;
with r do
try
CreateKey('Software\NameOf
OpenKey('Software\NameOfMy
a := ReadBool('IsRunning'); //read the value into A
CloseKey;
finally
free;
end;
if a = False then application.Terminate
end;
end.
Regards Barry
ASKER
Hi Barry,
Your tip is neat and lean. I like it. Thank you.
Your tip is neat and lean. I like it. Thank you.