[fpc-pascal] java events calling pascal code vs java calling library.
patspiper at gmail.com
Thu Apr 24 23:00:44 CEST 2014
On 24/04/14 22:53, fredvs wrote:
> Could it be possible to have some infos ans arguments about this :
> Im newbie in Java-link-with-fpc and I would like to understand what
> can/cannot be done.
> Here what i understood (If im wrong, please, correct me...)
> => All Java os (Android and friends) can only deal with Java class.
Normally yes. but JNI (Java Native Interface) allows java to comunicate
bi-directionally with native languages such as C.
> => If i want to use Pascal code, i need first to create a Java class and,
> via Java events-methods it is possible to execute Pascal code. The Pascal
> code is "inside" the Java class when compiling Java application.
Java can declare methods as being native and thus without an
implementation. The implementation should be in a library (dll, so, or
whatever) which is a C, Pascal, or other library. On the other hand,
pascal can call java methods, create java objects... using JNI
procedures. You can even mix so that java calls a pascal method which in
turn calls a java method.
I found out recently that it is possible to have a pascal program run in
android with some fixed java code only. This is still experimental
although the results are encouraging.
> => A other way to use Pascal code is via a Pascal library. You need to
> compile the fpc library with some "Java arguments", and so the fpc library
> is perfectly Java-compatible. The disadvantage is that you need to give that
> "external Java native library" with your application.
I am not sure what you mean, but it could be that I answered this above.
> => If giving that "external Java native library" with your application is
> not a problem,, using fpc library is much easier than using Pascal code via
> Java events-methods.
It depends what you want to achieve. If you are a java programmer, in
general better stick with java. If you have some fpc code that you want
to use with android (be it for speed or convenience), have java call the
fpc routines. If you don't know java, and don't want to learn it, then
let fpc be in charge, and call the android code for hardware access and
gui related stuff.
The good news is that I see the possibility of coding purely in pascal,
but progress is slow as my java exposure started only a few days ago.
Having said that, some or all of my post could be inaccurate. I hope
somebody with better knowledge can guide you better.
More information about the fpc-pascal