{"id":19538038,"url":"https://github.com/geoffsmith82/delphijniwrapper","last_synced_at":"2025-04-19T12:50:41.021Z","repository":{"id":134357518,"uuid":"589374271","full_name":"geoffsmith82/DelphiJNIWrapper","owner":"geoffsmith82","description":"Allows Delphi and Java to call each other","archived":false,"fork":false,"pushed_at":"2023-01-18T05:33:57.000Z","size":169,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T08:03:28.958Z","etag":null,"topics":["delphi","delphi-java","delphi-jni","java","jni"],"latest_commit_sha":null,"homepage":"","language":"Pascal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geoffsmith82.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-16T00:05:07.000Z","updated_at":"2024-12-04T12:56:08.000Z","dependencies_parsed_at":"2023-08-10T19:02:42.337Z","dependency_job_id":null,"html_url":"https://github.com/geoffsmith82/DelphiJNIWrapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffsmith82%2FDelphiJNIWrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffsmith82%2FDelphiJNIWrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffsmith82%2FDelphiJNIWrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geoffsmith82%2FDelphiJNIWrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geoffsmith82","download_url":"https://codeload.github.com/geoffsmith82/DelphiJNIWrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249699356,"owners_count":21312382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delphi","delphi-java","delphi-jni","java","jni"],"created_at":"2024-11-11T02:30:35.148Z","updated_at":"2025-04-19T12:50:40.996Z","avatar_url":"https://github.com/geoffsmith82.png","language":"Pascal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JNI Wrapper for Delphi and FreePascal\n\n    Contents of Archive\n    Notes on Use\n    Licensing Terms \n\nVersion: 2.95\n\nDate:\n\nApril 22, 2019\n\nAuthors:\n\nJonathan Revusky (Lead programmer), jon@revusky.com\n\nSalvatore Meschini (Maintainer), salvatoremeschini@interfree.it\n          \nAmine Moulay Ramdane has enhanced more JNI Wrapper and ported it to 64 bit and to all the Delphi versions and to Delphi Tokyo and to FreePascal and i have made it work with Java, my email is aminer68@gmail.com\n\nThis JNI Wrapper for Delphi and FreePascal provides a powerful and simplified object-oriented API for doing mixed language programming in Java and Delphi (Object Pascal language) or FreePascal. This may provide an easier and more productive way of getting Win32 and Win64 features in Java projects and integrating legacy code (at least for the Delphi or FreePascal community). Please read the readme file inside the zip file to learn more.\n\nI Amine Moulay Ramdane have noticed that JNIWrapper for Delphi and FreePascal was not supporting returning of Strings and Arrays types from Java, so i have implemented that and i have now enhanced JNI Wrapper to be very powerful , so it's now supporting all the necessary functions and methods and and much more... hope you will happy with it cause i have worked hard to bring this new 2.94 to you, it is really now a professional software of a good quality. \n\nAlso i Amine Moulay Ramdane have enhanced the JNI Wrapper more and ported it to 64 bit and to both FreePascal and the Delphi XE versions sanmd to Delphi Tokyo, here is the functions that i have implemented and added:\n```Pascal\nfunction JstringArrayToDTStrings(jarr : JArray) : TStrings;\n\nfunction JdoubleArrayToDdoubleArray(jarr : JdoubleArray) : TDdoubleArray;\n\nfunction JfloatArrayToDsingleArray(jarr : JFloatArray) : TDsingleArray;\n\nfunction JcharArrayToDwordArray(jarr : JCharArray) : TDwordArray;\n\nfunction JbyteArrayToDshortintArray(jarr : JByteArray) : TDshortintArray;\n\nfunction JshortArrayToDsmallintArray(jarr : JShortArray) : TDsmallintArray;\n\nfunction JbooleanArrayToDbooleanArray(jarr : JBooleanArray) : TDbooleanArray; \n```\nAnd don't forget to call TJavaVM.freeRef() method from Delphi or FreePascal when you need to garbage collect and free the memory that was allocated. \n\n***geoffsmith82:*** I have tidied up the code and Used Delphi Style function Capitalization for delphi code.  I removed hte Microsoft Java VM as it hasn't existed for probably 20 years after the lawsuit from Oracle.  Converted some functions from AnsiString to String.  I have been using Delphi 11.2.\n\nRead the rest:\n\n## Design Goal:\n\nTo provide a simplified object-oriented API for doing mixed language programming in Java and Delphi (Borland Object Pascal language) or FreePascal. This may provide an easier and more productive way of getting Win32 and Win64 features in Java projects and integrating legacy code (at least for the Delphi or FreePascal community).\nGeneral Description:\n\nThe accompanying files contain source code that makes it easy to implement mixed language projects with Java and Delphi or FreePascal. JNI.pas is a straight translation of the jni.h header file distributed with Sun's JDK. This can be used on its own with no restriction except those applying to the use of the Sun JDK (not to be used flying aircraft or operating nuclear facilities and whatnot.)\n\nThe files JNIWrapper.pas and JavaRuntime.pas contain the source code to wrapper classes I have written to provide a much easier object-oriented interface to the Java Native Interface (JNI). These classes include the following:\n\n    * TJavaRuntime is an encapsulation of the JNI Invocation API. In most cases, you will get an instance of this class by calling the class method GetDefault.\n    * TJavaParams is an encapsulation of the list of parameters passed to a Java method.\n    * TJavaObject is an encapsulation of a Java object.\n    * TJavaClass is an encapsulation of a Java class.\n    * TJavaMethod is an encapsulation of a Java method.\n\nUse of the above classes is demonstrated in the various .dpr and .java files that are included.\nNotes on Use of the JNI wrapper methods:\n\nUsage should be fairly intuitive, particularly from study of the included examples.\n\nIn this version, there is a pretty sophisticated wrapper around the invocation API. Typically, you instantiate a TJavaRuntime instance by calling the static method GetDefault, which will look for a Java runtime on your system. By default, it starts off looking for a Oracle Java JVM, and failing that, looks for a Sun 1.1 VM, and if it can't find that, looks for the MS VM. (Note that the latter will only work with the most recent JVM from Microsoft, the one that supports JNI.) You can give it hints by calling the methods SetPrefersMS and SetJava11 before calling GetDefault. If you do that, you change the order in which the method searches.\n\nYou can also specify directly which VM you want to instantiate by calling:\n\nTJavaRuntime.Create(\u003cchoice\u003e) where the choice can be one of:\nSunJava11, SunJava2, or MSJava.\n\nThis method will raise an exception if:\n\n    * You have already instantiated a JavaRuntime instance (you can only create one.)\n\n    * The JVM you specified cannot be found on the system.\n\nThe various run-time JVM options can be set via the properties MaxHeapSize, MinHeapSize, Verbose, etc. of the class TJavaRuntime. Note that these properties are effectively read-only after the VM is actually instantiated.\nNotes on calling Delphi or FreePascal methods from Java:\n\nAn example is provided of calling a Delphi or FreePascal DLL from Java. Note that in order to use the JNI wrapper methods, you must first call:\nTJavaVM.setThreadPenv(penv);\n\nat the top of your native method.\n\nThe other big gotcha in terms of calling a native Delphi or FreePascal DLL from Java involves threading issues. Delphi or FreePascal variables that are to be used in multiple threads should be declared in a threadvar section. Java objects wrappers that are to be used from multiple threads should be promoted to global references. This amounts to setting:\nJavaObject.Global := true;\n\nwith a TJavaObject (or TJavaClass) instance.\nDirect Use of JNI.pas:\n\nI anticipate that most people will prefer to call Java methods using the wrapper classes in JNIWrapper.pas and JavaRuntime.pas. However, not all of the JNI functionality is currently wrapped, so you may have to use JNI.pas directly. If you do that, the source in JNIWrapper.pas provides a fairly involved model of how to do so. Note that there is significant redundancy in the function pointers which are provided by the JNI. Most calls have three forms of parameter list that you can use, CallXXXMethod(), CallXXXMethodV(), and CallXXXMethodA(). The first form uses a C-style variable length parameter list. As far as I know, this has no Object Pascal equivalent. I have mostly opted to use the CallXXXMethodV calls, which basically work by passing a totally raw pointer to the list of arguments.\n\nThat is indeed about as ugly as it gets. However, the TJavaParams wrapper class is designed to shelter you from this ugliness. This class (in conjunction with TJavaMethod) also protects you from having to supply the Java method signature to obtain a reference to a Java method.\nContents of archive:\n\n    * JNI.pas -- translation of the jni.h file in the Sun JDK to Pascal.\n\n    * JNIWrapper.pas -- delphi source code containing object pascal class wrappers for JNI handles.\n\n    * JavaRuntime.pas -- delphi source code containing object pascal class TJavaRuntime that provides an easy-to-use wrapper around the JNI invocation API.\n\n    * JUtils.pas -- Source of various routines used here and there.\n\n    * JTest*.dpr -- These files contain delphi source of demos that show how to use the JNIWrapper.pas code in your programs.\n\n    * HelloWorld.java -- the source to a Java program that is used in JTest demos.\n\n    * native.dpr -- Source for a trivial DLL written in Delphi to demonstrate a native call to delphi from Java. The Java part of this demo is in the file NativeExample.java\n\n    * Bothways.dpr -- This provides an example in which Delphi code calls Java code and then viceversa!\n\n    * build.bat -- A command-line batch file which compiles all the included source files. It is assumed that you have the Delphi command line compiler DCC32.exe and the default Java command-line compiler javac.exe on your system path. Note: This code compiles with Delphi 4. I haven't tried it with any later version. Please tell me if there is a problem.\n\nPartial wish list:\n\n    * A delphi version of the javah tool that provides the stubs for java native methods.\n\n    * Better documentation.\n\n(Write me to add to this wishlist.)\n## License:\n\nOpen source. The library may be incorporated into your products as long as you specify in your banner (console mode) and/or about box (GUI mode) that you make use of this product and provide the URL where the user may obtain the latest version. That URL is currently:\n\nhttp://www.revusky.com/\n\nRedistribution of this product in source form must include this readme file.\n\nHave fun!\n\nJonathan Revusky, 1 May 2001\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeoffsmith82%2Fdelphijniwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeoffsmith82%2Fdelphijniwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeoffsmith82%2Fdelphijniwrapper/lists"}