<div dir="ltr">Hello everyone,<div><br></div><div>a couple years ago i tried the same thing. The task was to implement a JavaPOS driver handler from Delphi/FPC code. </div><div>The actual driver was implemented in C++ and it used a Java interface. My code was the glue between the application (Delphi/FPC) and the driver, it had to hook the events and call the appropriate methods for printing etc (it was a POS printer driver).</div>
<div><br></div><div>I found that the only way to hook a native implemented listener to the java class was either to write a small piece of code in java to do the dispatching to my code OR use dynamic compilation to create the Java byte code. Basically i had to write the java code inside my dll (in a constact string) and pass this to the Java compiler to create the byte code in memory.</div>
<div>This needed a lot of work and i dropped it since the actual java code was less than 30 lines and it was very generic, so it was not worth the effort. </div><div>Check this </div><div><a href="http://www.javablogging.com/dynamic-in-memory-compilation/">http://www.javablogging.com/dynamic-in-memory-compilation/</a></div>
<div><br></div><div>This needs Java 6 (which was not an option in my case, i had to use older versions). It might help you.</div><div>Also it needs to store the source files locally otherwise more dynamic class generation will be needed.</div>
<div>The link above has the info you need.</div><div><br></div><div>Chriss</div><div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 23, 2014 at 12:31 PM, Felipe Monteiro de Carvalho <span dir="ltr"><<a href="mailto:felipemonteiro.carvalho@gmail.com" target="_blank">felipemonteiro.carvalho@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">On Wed, Apr 23, 2014 at 6:10 AM, leledumbo <<a href="mailto:leledumbo_cool@yahoo.co.id">leledumbo_cool@yahoo.co.id</a>> wrote:<br>
> Hmm...that's beyond my Java skill. Since Felipe who started the topic, you<br>
> can try PM him instead.<br>
<br>
</div>So looking at what he originally posted:<br>
<br>
setOnCompletionListener(MediaPlayer.OnCompletionListener listener)<br>
<br>
And looking into the documentation:<br>
<br>
<a href="http://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html" target="_blank">http://developer.android.com/reference/android/media/MediaPlayer.OnCompletionListener.html</a><br>
<br>
you need to provide a class which implements the<br>
MediaPlayer.OnCompletionListener interface:<br>
<br>
There is nothing in JNI unfortunately which would allow us to create<br>
new classes. JNI is very limited, unlike objc runtime which gives us<br>
access to everything, JNI gives us a limited access to the Java world.<br>
<br>
I already asked in the past in Java/Android groups about this, how to<br>
get rid of Java when you need to pass a class which implements and<br>
interface.<br>
<br>
The answer is that it is possible: You need to create the class in<br>
...... java bytecode =D And then pass it to Java.<br>
<br>
At this point I gave up, considering it too awkward and wrote my<br>
software part in Java and part in Pascal.<br>
<br>
Ideally it would not be so hard if we had a bytecode generator which<br>
accepts as input things like classname, which interfaces it will<br>
implement, list of functions and address to their implementation, etc,<br>
etc. But we don't have at the moment AFAIK.<br>
<br>
So maybe someone braver will actually do this, since it is possible =D<br>
But I didn't for my Android app in the app store (True Democracy)....<br>
<span class=""><font color="#888888"><br>
--<br>
Felipe Monteiro de Carvalho<br>
</font></span><div class=""><div class="h5">_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br></div></div></div>