Link to home
Start Free TrialLog in
Avatar of henrylim
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.
Avatar of viktornet
viktornet
Flag of United States of America image

not sure what you mean... sorry..
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh i see now... you can use FindExecutable() in order to find the path to your MAN EXE file...

Good Luck!!

..-=ViKtOr=-..
MAN=MAIN
Avatar of inthe
inthe

MAN=MAIN <--True in my house anyway  ;-)
Avatar of henrylim

ASKER

Hi Inth,
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
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\NameOfMyProgram');   //create the registry key
 OpenKey('Software\NameOfMyProgram', False); //open it
 WriteBool('IsRunning',a);    //write our value to the registry
{look in  delphi help files for many other registry functions,writebinarydata,writestring,writeinteger 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\NameOfMyProgram');
 OpenKey('Software\NameOfMyProgram', 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\NameOfMyProgram');
 OpenKey('Software\NameOfMyProgram', False);
 a := ReadBool('IsRunning');    //read the value into A
 CloseKey;
 finally
  free;
 end;
 if a = False then application.Terminate
end;

end.



Regards Barry


Hi Barry,
Your tip is neat and lean.  I like it.  Thank you.