Recent

Author Topic: TProcess - 2 instances instead of 1  (Read 4013 times)

p0z1tr0n

  • Newbie
  • Posts: 1
TProcess - 2 instances instead of 1
« on: July 18, 2010, 02:27:01 pm »
Im writing a simple program that will helps urban-terror Linux gamers. Here my sample of code:
Code: [Select]
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;
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

  • Hero Member
  • *****
  • Posts: 8776
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TProcess - 2 instances instead of 1
« Reply #1 on: July 19, 2010, 09:13:47 am »
Try using nested if, e.g.:
Code: [Select]
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;

 

TinyPortal © 2005-2018