Forum > Beginners

Running external program (*.exe file) problem.

(1/3) > >>

TomTom:
I have Edit1.text:='C:\Cytadela\cytadela.exe'; I can run this program (game) on my system without any problem just by double clicking on it.
But I have something like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);var  gametitle, lasttimeplayed, timesplayed: String;  b: LongInt;  I: Integer;begin      GameProcess := TProcess.Create(nil);            GameProcess.Executable:=exepath.text; //exePath == TEdit      GameProcess.Execute;end;  
Screen resolutions changes and goes black and app is being closed. When I run this game by clicking on exe it runs just fine but in a window. What can be the cause of that?

Thaddy:
On Windows, Lazarus has by default no immediate console support, because a GUI application does not usually need it.
If you define {$apptype console} at the top of the lpr file it probably works. Note it takes some more work to hide the console window until it is needed and hide it again after the external program is finished.
But actually that is quite easy.

KodeZwerg:

--- Quote from: TomTom on November 29, 2022, 01:56:44 pm ---What can be the cause of that?

--- End quote ---
You probably free it too early.

I suggest to write it like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button3Click(Sender: TObject);var   AProcess: TProcess;begin  if (not FileExists(exepath.text)) then    begin      ShowMessage('Not found!');      Exit;    end;  AProcess := TProcess.Create(nil);  AProcess.Executable:= exepath.text;  AProcess.Parameters.Add('');  AProcess.Options := AProcess.Options + [poWaitOnExit];  AProcess.Execute;  AProcess.Free;   end. Please test and tell if there is still something wrong.

TomTom:
I simplified the code in my post. I did it like You wrote. There is no difference. For example other apps run without problem... May it be because the game is in SDL ?
I also tried ShellExecute but effect is the same in this case.

I just want the app to start just like I would click on it in windows explorer. I don't care if there is console or not.

KodeZwerg:

--- Quote from: TomTom on November 29, 2022, 02:11:04 pm ---I simplified the code in my post. I did it like You wrote. There is no difference. For example other apps run without problem... May it be because the game is in SDL ?

I just want the app to start just like I would click on it in windows explorer. I don't care if there is console or not.

--- End quote ---
Do you have "AProcess.Options := AProcess.Options + [poWaitOnExit];" added, yes?

Navigation

[0] Message Index

[#] Next page

Go to full version