[fpc-pascal] JNI/Android: Java events calling pascal code

Chriss Kalogeropoulos iz.iznogood at gmail.com
Wed Apr 23 22:40:22 CEST 2014


The main reason is to avoid distributing extra files with the application.
Having just one exe or dll that can handle the "details" is much better.

I was also hoping to reuse the code in other similar projects that had
different listeners. For example, a barcode reader javapos driver has
different event signatures (different listener class), so it needs
different java code. It would be nice if it could be encapsulated inside
the pascal class instead of an external file.

Anyway the task is doable if someone can write the java code in a temporary
file and invoke the compiler. If this is not possible I do not know if it
can be done.

If you do not care about that then just use java glue code, it's simpler.
 Στις 23 Απρ 2014 2:34 μ.μ., ο χρήστης "patspiper" <patspiper at gmail.com>
έγραψε:

On 23/04/14 13:20, Chriss Kalogeropoulos wrote:

> Hello everyone,
>
> a couple years ago i tried the same thing. The task was to implement a
> JavaPOS driver handler from Delphi/FPC code.
> 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).
>
> 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.
> 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.
> Check this
> http://www.javablogging.com/dynamic-in-memory-compilation/
>
> This needs Java 6 (which was not an option in my case, i had to use older
> versions). It might help you.
> Also it needs to store the source files locally otherwise more dynamic
> class generation will be needed.
> The link above has the info you need.
>

If the java code is static, why would one need dynamic compilation?

Stephano

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140423/e614df15/attachment.html>


More information about the fpc-pascal mailing list