Jump to content
Felix.

Is there analog of C#'s in Firemonkey?

Recommended Posts

Greetings to all,

there's a useful piece of code in C# that can run process under Android:

        mProcess = new Process();
        ProcessStartInfo si = new ProcessStartInfo()
        {
            FileName = filepath,
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardError = true,
            RedirectStandardInput = true,
            RedirectStandardOutput = true
        };
        mProcess.StartInfo = si;
        mProcess.OutputDataReceived += new DataReceivedEventHandler(MProcess_OutputDataReceived);
        mProcess.Start();
        mProcess.BeginErrorReadLine();
        mProcess.BeginOutputReadLine();

Then it can send and receive commands to/from a file (program).

 

Is there such analog in Delphi? (Firemonkey)

Thanks!

 

Edited by Felix.

Share this post


Link to post
2 hours ago, Felix. said:

Is there such analog in Delphi?

Not "out of the box". Here's a link that includes the Java equivalent:

 

https://stackoverflow.com/a/5642593/3164070

 

..and an import for the Process and Runtime classes:

 

https://github.com/DelphiWorlds/Kastri/blob/master/API/DW.Androidapi.JNI.Lang.pas

 

That should at least give you a start

  • Thanks 1

Share this post


Link to post

Yes, you're correct, but the demo would be perfect. Even Delphi comes with a huge number of demos,examples and snippets

Share this post


Link to post
11 hours ago, Felix. said:

Yes, you're correct

You still have not explained what are you aiming to do specifically. It may be that whatever it is, can be done some other way.

 

11 hours ago, Felix. said:

Even Delphi comes with a huge number of demos,examples and snippets

 

Yes - they're part of a commercial product, i.e. people are paid to write them.

Share this post


Link to post

I need to run stockfish engine, send uci commands to it and get the result. There are no examples for Delphi Firemonkey. It's not hard to make it work under Windows, but under Android...

Share this post


Link to post
8 hours ago, Felix. said:

There are no examples for Delphi Firemonkey. It's not hard to make it work under Windows, but under Android.

There's now an example of how to run a process on Android, here:

 

https://github.com/DelphiWorlds/HowTo/tree/main/Demos/AndroidRunProcess

 

Sadly, I have been unable to make it work with the Stockfish application that is available for download here:

 

https://stockfishchess.org/download/

 

The process seems to start, however it also seems to lock up my application. There does not seem to be any clues in the device logcat messages as to what the problem is. The demo still includes the files, and the code that attempts to run it, however the code has been commented out in favour of some more basic executables that are known to work. 

 

I have put my efforts on hold (though I may use the run process code myself for something else), and have thrown it open to anyone else who might be able to make it work.

  • Thanks 1

Share this post


Link to post

Thank you, a very useful demo.

Maybe we need to apply chmod to stockfish file. I'll try it today.

Share this post


Link to post
3 hours ago, Felix. said:

Maybe we need to apply chmod to stockfish file

I thought I would have received an error indicating that it could not be executed. I also used TFile.GetAttributes to check whether it could be (it has all the execute attributes), and running ls -l on the containing folder (using the demo itself) suggests that it is executable:

 

image.thumb.png.b43d888b73dc8615f7036d509c3e8067.png

Share this post


Link to post
On 12/7/2021 at 7:47 PM, Dave Nottage said:

It's used by one of the other units, DW.RunProcess.Android.pas

Dave,

should your RunProcess application (built with Delphi 10.4.1) work under Android 11?

I created an APK file, installed it, but after I run the application, it immediately closes.

Share this post


Link to post
2 minutes ago, Felix. said:

should your RunProcess application (built with Delphi 10.4.1) work under Android 11?

It runs on my Android 11 device when I build it with Delphi 11. If you're using 10.4.1, you should go to the Libraries node under the Android platform in Project Manager, right click it and click Revert System Files To Default. Like this, but you're going back a version:

 

https://github.com/DelphiWorlds/HowTo/tree/main/Solutions/AndroidLibraries

  • Thanks 1

Share this post


Link to post
8 minutes ago, Dave Nottage said:

Like this, but you're going back a version:

 

 

Is Delphi 10.4.1 still good to create Android applications? I don't plan to buy Alexandria.

Edited by Felix.

Share this post


Link to post
2 minutes ago, Felix. said:

Is Delphi 10.4.1 still good to create Android applications?

if you're planning on deploying to the Play Store, staying current is a better option.

  • Like 1

Share this post


Link to post
Just now, Dave Nottage said:

if you're planning on deploying to the Play Store, staying current is a better option.

Ok, I got it. One more question please: on github there are two your projects: Kastri (Cross-platform library for Delphi) and KastriFree (Free version of the Kastri library). Isn't Kastri free?

Share this post


Link to post
1 minute ago, Felix. said:

on github there are two your projects: Kastri (Cross-platform library for Delphi) and KastriFree (Free version of the Kastri library). Isn't Kastri free?

I had originally planned on having a commercial version, however those plans changed. Now Kastri is driven mostly by sponsorship and one-off donations. Kastri Free is deprecated and developers should use Kastri instead.

  • Thanks 1

Share this post


Link to post
On 12/7/2021 at 10:29 AM, Dave Nottage said:

There's now an example of how to run a process on Android, here:

 

https://github.com/DelphiWorlds/HowTo/tree/main/Demos/AndroidRunProcess

 

Sadly, I have been unable to make it work with the Stockfish application that is available for download here:

 

https://stockfishchess.org/download/

 

The process seems to start, however it also seems to lock up my application. There does not seem to be any clues in the device logcat messages as to what the problem is. The demo still includes the files, and the code that attempts to run it, however the code has been commented out in favour of some more basic executables that are known to work. 

 

I have put my efforts on hold (though I may use the run process code myself for something else), and have thrown it open to anyone else who might be able to make it work.

Dave, in your project there is a comment "// Use this method only when you are certain the process being run is waiting for input"

 

how can we determine using your units if the process is running or it was closed?

Share this post


Link to post
6 hours ago, Felix. said:

how can we determine using your units if the process is running or it was closed?

Use the IsRunning property

Share this post


Link to post
15 hours ago, Dave Nottage said:

Use the IsRunning property

I got this message for all libraries I run:

Process terminated with exit code: 0

 

So I can't send anything, because they always not running

Share this post


Link to post
8 hours ago, Felix. said:

So I can't send anything, because they always not running

Which libraries are they? Have you read their documentation to see if they actually wait for input while they're running?

Share this post


Link to post
21 minutes ago, Dave Nottage said:

Which libraries are they? Have you read their documentation to see if they actually wait for input while they're running?

I suspect that stockfish engine waits for input, that's why it locks the application.

Have no idea how to send input data to stockfish.

Share this post


Link to post
1 hour ago, Felix. said:

I suspect that stockfish engine waits for input, that's why it locks the application.

You said you are running apps that result in: Process terminated with exit code: 0. Stockfish just locked up on me - regardless of whether or not it's waiting for input, that's not what you described

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×