Ranja AZ 2 Posted March 18, 2021 Here is an instruction that I cannot convert to delphi: printer.startPrint(false, new OnPrintListener() { //roll paper or not @Override public void onPrintResult(final int retCode) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(PrinterActivity.this, retCode + "", Toast.LENGTH_SHORT).show(); } }); } }); Regard. Share this post Link to post
Guest Posted March 18, 2021 in your IDE, you should have the tool for that Java2OP you can try yourself with this tools by Oliver Funcke http://cc.embarcadero.com/Item/29831 for commercial use you can try WinSoft Java4Delphi https://blogs.embarcadero.com/convert-java-class-files-and-jar-archive-files-into-delphi-modules-using-the-java4delphi-tool/ hug Share this post Link to post
Ranja AZ 2 Posted March 18, 2021 Thank you for your reply! I have a java file (attached file) and I have java4delphi, can I convert this java file to .pas file with this tools? Please How to do that? Regard. PrinterActivity.java Share this post Link to post
Guest Posted March 18, 2021 You need to state your "environment". And what you are trying to achieve. It's not very clear. Do you want to writ Pascal and execute it as JS? Do you want to convert (transplie) Pascal to JS and run the JS in... webbrowser or node.js? What do you want to do? First you ask "Pascal => Java". Then you state "i have a jar". Witch way? What is your needs? What are you doing? At all? Share this post Link to post
Dave Nottage 557 Posted March 18, 2021 4 hours ago, Ranja AZ said: can I convert this java file to .pas file with this tools? Unlikely. Such tools are to create imports from .jar or .class files, not convert Java code to Delphi. Your main problem will be whether OnPrintListener is a class or an interface, because you cannot implement a descendant of a Java class in Delphi - it needs to be done in Java. Java interfaces however, can be implemented in Delphi by creating a descendant of TJavaLocal, and implementing the interface in question. There are a number of examples of descendants of TJavaLocal throughout the Delphi source. In order to determine what OnPrintListener is, you could use the aforementioned tools to import the Java classes from the .jar that you mentioned, assuming that it is the one that contains com.nexgo.oaf.apiv3. Share this post Link to post
Ranja AZ 2 Posted March 18, 2021 I want to convert java code to delphi code. My problem is the call to new OnPrintListener () in the parameter. Regard Share this post Link to post
Guest Posted March 18, 2021 try use Eclipse for "export the class to Delphi" https://www.eclipse.org/downloads/ see Android Studio, too! https://developer.android.com/studio hug Share this post Link to post
limelect 48 Posted March 19, 2021 (edited) @emailx45 17 hours ago, emailx45 said: see Android Studio, too! https://developer.android.com/studio hug are you sure about Android Studio? if so how? No export that does it Edited March 19, 2021 by limelect Share this post Link to post
Dave Nottage 557 Posted March 19, 2021 22 hours ago, Ranja AZ said: I want to convert java code to delphi code. It appears you have already asked a similar question, here: https://stackoverflow.com/questions/65345853/is-it-possible-to-write-the-following-java-program-in-delphi The principal for your present issue is identical, i.e. if OnPrintListener is a class, then you. cannot do it in Delphi. If it's an interface (which, given your other question, it's likely), then you already have an example of how to implement a Java interface, in the StackOverflow answer. A possible example for this case: uses Androidapi.JNIBridge, Androidapi.JNI.JavaTypes, Androidapi.Helpers; type JOnPrintListener = interface; JOnPrintListenerClass = interface(IJavaClass) ['{076904DD-77D9-497D-BA21-992A9B8FED3E}'] end; [JavaSignature('com.nexgo.oaf.apiv3.device.printer.OnPrintListener')] JOnPrintListener = interface(IJavaInstance) ['{F688775D-067F-4521-A045-9106599F4C4A}'] procedure onPrintResult(retCode: Integer); cdecl; // *** NOTE *** There may be other methods for this interface end; TJOnPrintListener = class(TJavaGenericImport<JOnPrintListenerClass, JOnPrintListener>) end; TRunnable = class(TJavaLocal, JRunnable) private FCallback: TProc; public { JRunnable } procedure run; cdecl; public constructor Create(const ACallback: TProc); end; TPrintListener = class(TJavaLocal, JOnPrintListener) private FRetCode: Integer; FRunnable: JRunnable; procedure DoRun; public { JOnPrintListener } procedure onPrintResult(retCode: Integer); cdecl; public constructor Create; end; { TRunnable } constructor TRunnable.Create(const ACallback: TProc); begin inherited Create; FCallback := ACallback; end; procedure TRunnable.run; begin FCallback; end; { TPrintListener } constructor TPrintListener.Create; begin inherited; FRunnable := TRunnable.Create(DoRun); end; procedure TPrintListener.DoRun; begin // Do the toast thing here, using FRetCode end; procedure TPrintListener.onPrintResult(retCode: Integer); begin FRetCode := retCode; TAndroidHelper.Activity.runOnUiThread(FRunnable); end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin // Assuming FPrintListener is defined as: FPrintListener: JOnPrintListener FPrintListener := TPrintListener.Create; // Assuming you have created an instance of Printer (imported as JPrinter) called FPrinter FPrinter.startPrint(False, FPrintListener); end; Note all of the assumptions being made - the biggest one being that OnPrintListener is an interface. Also I don't have the .jar, nor the printer, so of course it is untested 3 Share this post Link to post
Ranja AZ 2 Posted March 20, 2021 Thank you Dave! Your explanation is very clear. Now printing is OK now. Thank you so much. Regard Share this post Link to post