There is a utility that was recently released called Java2Pas and it creates an interface out of a Java class or Jar file for Delphi XE5 Firemonkey. The goal being that it will allow you to create interface files for all kinds of Android JAR libraries. There is not much information about the utility but it appears to come from a company called Software Union in Luxembourg. It seems like the utility is a paid utility with a free version but I don’t see anywhere to register it. When you create an interface file it is labeled with “unregistered evaluation copy” text (there is also an ini file with a place for a key). Update: You can email them to purchase via Paypal or wire (the cost is EUR 50 + VAT). In any event the utility creates interface(JObjectClass)’s for all class files but will only create interface(JObject)’s for classes in the Android namespace. I’m not sure how useful it is without the JObject interfaces however. There is a post up on DelphiPraxis where the author explains the utility here. On the forum post the example interface is the AlarmManager from Android. I used the utility against the SQLCipher JAR file and this is some of what it created:
//
// Generated by JavaToPas 20140406 - 210726
// *** unregistered evaluation copy ***
////////////////////////////////////////////////////////////////////////////////
unit net.sqlcipher.database.SQLiteDatabase;
interface
uses
AndroidAPI.JNIBridge,
Androidapi.JNI.JavaTypes,
net.sqlcipher.database.SQLiteTransactionListener,
net.sqlcipher.database.SQLiteDatabase_CursorFactory,
net.sqlcipher.database.SQLiteDatabaseHook,
Androidapi.JNI.GraphicsContentViewText,
net.sqlcipher.database.SQLiteClosable,
net.sqlcipher.SQLException,
net.sqlcipher.database.SQLiteDatabase_SyncUpdateInfo,
net.sqlcipher.database.SQLiteDatabaseCorruptException,
net.sqlcipher.database.SQLiteStatement,
net.sqlcipher.Cursor,
net.sqlcipher.database.SQLiteCursorDriver,
net.sqlcipher.database.SQLiteCursor,
android.content.ContentValues,
net.sqlcipher.database.SQLiteCompiledSql,
android.util.Pair;
type
JSQLiteDatabase = interface;
JSQLiteDatabaseClass = interface(JObjectClass)
['{9366527F-7E37-4BEF-9E18-93E69A02D5CA}']
function compileStatement(sql : JString) : JSQLiteStatement; cdecl;Â Â Â Â Â Â Â Â // (Ljava/lang/String;)Lnet/sqlcipher/database/SQLiteStatement; A: $1
function create(factory : JSQLiteDatabase_CursorFactory; password : JString) : JSQLiteDatabase; cdecl;// (Lnet/sqlcipher/database/SQLiteDatabase$CursorFactory;Ljava/lang/String;)Lnet/sqlcipher/database/SQLiteDatabase; A: $9
function delete(i : Integer; numArgs : Integer; e : JSQLiteDatabaseCorruptException; table : JString; whereClause : JString; whereArgs : TJavaArray<JString>; statement : JSQLiteStatement) : Integer; cdecl;// (Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)I A: $1
function findEditTable(spacepos : Integer; commapos : Integer; tables : JString) : JString; cdecl;// (Ljava/lang/String;)Ljava/lang/String; A: $9
[...]
end;
[JavaSignature('net/sqlcipher/database/SQLiteDatabase$ActiveDatabases')]
JSQLiteDatabase = interface(JObject)
['{DB8BBC42-3A10-47B7-882B-DAA528BE65C0}']
//
// Unregistered copy: Implementation not written
//
end;
There are two other utilities that I know of that will create interface files out of class files for Android. The first one, Android 2 Delphi Import tool, has no free trial and has to be purchased with Bitcoins. The second one, JavaImport For Android, has a free trial but only works on Java class files directly and not on JAR files. I’d like to see JavaImport handle JAR files directly.
Head over and download the Java2pas utility from the Software Union website.
JavaImport 1.4 supports folders with .class files, so .jar file can be easily converted by renaming to .zip and unzipping to some folder.
JavaImport trial version is available at http://www.winsoft.sk/jimport.htm
You can now order the commercial version also via
Share-It link http://tinyurl.com/prvgbgu
Does it work for jTDS java library ? (Web site: http://jtds.sourceforge.net/)
Can you write simple example sql connection with using jTDS library ?
If work (i’m not sure), I want to buy your library…
Regards,
FK
I see quite a few people when I search Google who have gotten jTDS working on Android from a normal Android SDK app. Example:
http://amitku.wordpress.com/2011/08/03/how-to-connect-and-access-sql-database-server-from-android-app/
Not an easy thing to accomplish. Here is one way to load a JAR at runtime from Delphi XE5:
http://www.pclviewer.com/android/androidJNI.html
The conversion for the jTDS library runs flawlessly with Java2pas. However, it would still require a significant amount of work to invest to get it running, as mentioned in admin’s post. The question ist, what you want to accompish. Maybe in this case it would be better and also more safe to use DataSnap if you wish to access MSSQL from mobile.
See JDBC for Android library. It uses jTDS JDBC driver and MS SQL connection
demo example is included:
http://www.winsoft.sk/ajdbc.htm
Erik Salaj
is it possible to import third party libraries .JAR files in Delphi like this http://www.b4x.com/android/forum/threads/libgdx.32594/ ?
Yes, in Delphi XE7 you can just add the JAR file to the Library section of the project. Then you use the Java2OP tool to create a JNI interface file.
http://www.fmxexpress.com/create-android-java-jar-interface-files-for-delphi-xe7-firemonkey-with-java2op/