Forum > General
Cannot run a process procedure in a thread
glubbish:
Not easy to find examples.
Does not seem to work for me.
--- 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 RunProcess;var AProcess: TAsyncProcess;
on compile gives:
main.pas(63,19) Error: Identifier not found "TAsyncProcess"
I am currently getting the output with the current TProcess procedure.
--- 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 RunProcess;var AProcess: TProcess; AStringList: TStringList; i: integer = 0; percent: real; DisplayPercent: integer;begin AProcess := TProcess.Create(nil); // Create Process. (nil) means it must be freed. AProcess.Executable := MkvMerge; // Tell the new AProcess what the command to execute is. AProcess.Parameters.Add(MyParameter); // Pass MkvMerge parameters to the program AProcess.Options := AProcess.Options + [poUsePipes]; // Use Pipes so we can check output AProcess.ShowWindow := swoShow; // Hide the console window AProcess.Execute; // Now let AProcess run the program while AProcess.running = True do // Show its working via counter begin Inc(i); sleep(16); Application.ProcessMessages(); percent := ((i * 568125.96) / MySize) * 100; DisplayPercent := trunc(percent); if DisplayPercent > 100 then DisplayPercent := 100; Form1.Display.Cells[3, CurrentRow] := 'Processing (' + IntToStr(DisplayPercent) + '%)'; end; AStringList := TStringList.Create; // Keep the output AStringList.LoadFromStream(AProcess.Output); case AProcess.ExitCode of // Check for errors 1: begin // This is a warning. Display it and choose if we continue If timestamp out of order, then fix manually and run again. for i := 0 to AStringList.Count - 1 do if MessageDlg('Continue?', AStringList.Strings[i], mtConfirmation, [mbYes, mbNo], 0) = mrNo then begin AStringList.Free; AProcess.Free; halt(AProcess.ExitCode); end; end; 2: begin // This is an error. Display it, but no choice to continue. Also free for i := 0 to AStringList.Count - 1 do ShowMessage(AStringList.Strings[i]); AStringList.Free; AProcess.Free; halt(AProcess.ExitCode); end; end; AStringList.Free; // This is not reached until MkvMerge stops running. AProcess.Free;end;
Remy Lebeau:
--- Quote from: glubbish on July 04, 2024, 09:17:18 am ---
--- 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 RunProcess;var AProcess: TAsyncProcess;
on compile gives:
main.pas(63,19) Error: Identifier not found "TAsyncProcess"
--- End quote ---
TAsyncProcess is declared in the AsyncProcess unit, did you add that unit to your uses clause?
glubbish:
Application.Processmessages did not help
Using asyncprocess did not work either.
I cannot bring this form to the foreground when it is running, I have to minimize all other windows.
Threads were not working, but in the version I went from MyThread := TMyThread.Create(True); to
MyThread := TMyThread.Create(False);
MyThread.Start.
This gives an access violation on MyThread.Start.
This version attached.
Thaddy:
All wrong. will post an answer later with working code..
Meanwhile read up on threads.
Start here:
https://www.seti.net/engineering/threads/threads.php
Everything there compiles with fpc 100%
cdbc:
Hi
...and remember:
--- Quote ---"The theoreticians have proven that this is unsolvable, but there's three of us, and we're smart ..."
--- End quote ---
Hehehe... I just love it :D ;D :D
Regards Benny
Navigation
[0] Message Index
[#] Next page
[*] Previous page