java events calling pascal code vs java calling library.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

java events calling pascal code vs java calling library.

fredvs
Hello.

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.

=> 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.

=> 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.

=> 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.

Please, where im wrong, what else must i know... ?

Many thanks.

Fred
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: java events calling pascal code vs java calling library.

patspiper
On 24/04/14 22:53, fredvs wrote:
> Hello.
>
> 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.

Stephano
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: java events calling pascal code vs java calling library.

fredvs
Many thanks Stephano.

>> as my java exposure started only a few days ago.

Same for me. I have successfully adapt some of my fpc native libraries into Java-native libraries.
Im extremely happy with the result, all the functions/procedures are exported and working. Even callback procedures.

I am only blocked how to create a Java wrapper class for those libraries... All Java , code-guru, stackoverflow forum cannot help me...

Without that "library wrapper" class, i have to declare all the native methods of the library inside the main Java class.

But it works perfectly...
Many thanks ;-)
Reply | Threaded
Open this post in threaded view
|

Re: java events calling pascal code vs java calling library.

leledumbo
Administrator
In reply to this post by fredvs
> All Java os (Android and friends) can only deal with Java class.

Wrong. http://developer.android.com/reference/android/app/NativeActivity.html (not a single line of Java required)