Forum > General

TProcess - 2 instances instead of 1

(1/1)

p0z1tr0n:
Im writing a simple program that will helps urban-terror Linux gamers. Here my sample of code:

--- Code: ---procedure TForm1.LAUNCHURTClick(Sender: TObject);
begin
     if  (SECONDXCHECKBOX.Checked = False and MUMBLEOVERLAYCHECKBOX.Checked = False) then
     begin
          cmdopts := ' +name ' + NICK.Text + ' +connect ' + IPADDRESS.Text;
          cmdopts1 := ' +password ' + PWFIELD.Text;
          AProcess := TProcess.Create(nil);
          AProcess.CommandLine := BINARYPATH.Text + cmdopts + cmdopts1;
          AProcess.Execute;
     end;
     if  (SECONDXCHECKBOX.Checked = True and MUMBLEOVERLAYCHECKBOX.Checked = False) then
     begin
          cmdopts := ' +name ' + NICK.Text + ' +connect ' + IPADDRESS.Text;
          cmdopts1 := ' +password ' + PWFIELD.Text;
          AProcess := TProcess.Create(nil);
          AProcess.CommandLine := 'xinit ' + BINARYPATH.Text + cmdopts + cmdopts1 + ' -- :1';
          AProcess.Execute;
     end;
     if  (SECONDXCHECKBOX.Checked = False and MUMBLEOVERLAYCHECKBOX.Checked = True) then
     begin
          cmdopts := ' +name ' + NICK.Text + ' +connect ' + IPADDRESS.Text;
          cmdopts1 := ' +password ' + PWFIELD.Text;
          AProcess := TProcess.Create(nil);
          AProcess.CommandLine := '/usr/bin/mumble-overlay ' + BINARYPATH.Text + cmdopts + cmdopts1;
          AProcess.Execute;
     end;
     if  (SECONDXCHECKBOX.Checked = True and MUMBLEOVERLAYCHECKBOX.Checked = True) then
     begin
          Xoverlay := 'xinit /usr/bin/mumble-overlay ';
          cmdopts := ' +name ' + NICK.Text + ' +connect ' + IPADDRESS.Text;
          cmdopts1 := ' +password ' + PWFIELD.Text;
          AProcess := TProcess.Create(nil);
          AProcess.CommandLine := Xoverlay + BINARYPATH.Text + cmdopts + cmdopts1 + ' -- :1';
          AProcess.Execute;
     end;
end;
--- End code ---
TProcess options - poWaitOnExit

When I check MUMBLEOVERLAYCHECKBOX - second instance of ioUrbanTerror will be also launched. The question is: How to launch only one instance?

Leledumbo:
Try using nested if, e.g.:

--- Code: ---if SECONDXCHECKBOX.Checked then begin
  if MUMBLEOVERLAYCHECKBOX.Checked then begin
    ... // SECONDXCHECKBOX.Checked and MUMBLEOVERLAYCHECKBOX.Checked
  end else begin
    ... // SECONDXCHECKBOX.Checked and not MUMBLEOVERLAYCHECKBOX.Checked
  end;
end else begin
  if MUMBLEOVERLAYCHECKBOX then begin
    ... // not SECONDXCHECKBOX.Checked and MUMBLEOVERLAYCHECKBOX.Checked
  end else begin
    ... // not SECONDXCHECKBOX.Checked and not MUMBLEOVERLAYCHECKBOX.Checked
  end;
end;

--- End code ---

Navigation

[0] Message Index

Go to full version