Err...it's kinda overkill just to test a little piece of code
theclass := (PEnv^^).FindClass(PEnv,'MyCallbackClass') ; ///// => the problem
library mycallbacklib; uses jni;...vartheclass : JClass; //// => This added......procedure JavaInit( PEnv: PJNIEnv; Obj: JObject ; MClass : Jstring); cdecl;varMainClass : Pchar ;begin MainClass := (PEnv^^).GetStringUTFChars(PEnv, MClass, nil); /// Here MClass is Jtring theclass := (PEnv^^).FindClass(PEnv,MainClass) ; (PEnv^^).ReleaseStringUTFChars(PEnv, MClass, nil);end; procedure libcallback(PEnv: PJNIEnv; Obj: JObject); cdecl;var theproc : PChar; theMethod: JMethodID;begin theproc := (PEnv^^).GetStringUTFChars(PEnv, 'callback', nil); theMethod := (PEnv^^).GetStaticMethodID(PEnv, theclass, theproc,'()V') ; (PEnv^^).CallVoidMethod(PEnv,Obj,theMethod) ; // run the callback...end;...exports... libcallback name 'Java_MyCallback_libcallback',JavaInit name 'Java_MyCallback_javainit;...beginend.
public class MyCallback { public static void callback() { System.out.println("Yep, it works..."); } public static native void javainit(String st); //// => this is added public static native void libcallback(); public static void main(String[] args) { System.loadLibrary("mycallbacklib"); javainit("MyCallback"); libcallback(); }}