Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-04

java events calling pascal code vs java calling library.

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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 ;-)

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/java-events-calling-pascal-code-vs-java-calling-library-tp5719036.html Sent from the Free Pascal - General mailing list .

Reply by email

patspiper
to fredvs
fredvs wrote 9 lines
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.

Show quoted text 5 lines
=> 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

Reply by email

fredvs
to patspiper

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 by email

leledumbo
to fredvs: Hello. Could it be possible to have some infos ans arguments about this : Im newbie in…
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)

Reply by email