dcsimg
Calling Delphi forms in DLL from Java
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stelios_Gerogiannakis
Posted On:   Tuesday, June 11, 2002 10:18 AM

Hello all, I have the following problem: I want to use an existing Delphi form in a DLL. The wrapper code has been created using JavaToDPR (http://home.pacifier.com/~mmead/jni/delphi/JavaToDPR), a javah-like tool for Object Pascal. The DLL loads all-right and calls from Java to Delphi methods are OK. When it comes to displaying the form, though, here comes trouble! The form is displayed "frozen" (no dragging, no mouse events, no repainting). This causes all of the application to rfuse to terminate normally (via System.exit()), so I have to Ctrl+C the Java window. I suspect it has something to do with how Delphi "understands" the ca   More>>

Hello all,


I have the following problem:
I want to use an existing Delphi form in a DLL.
The wrapper code has been created using JavaToDPR (http://home.pacifier.com/~mmead/jni/delphi/JavaToDPR), a javah-like tool for Object Pascal.


The DLL loads all-right and calls from Java to Delphi methods are OK.
When it comes to displaying the form, though, here comes trouble!


The form is displayed "frozen" (no dragging, no mouse events, no repainting).
This causes all of the application to rfuse to terminate normally (via System.exit()), so I have to Ctrl+C the Java window.


I suspect it has something to do with how Delphi "understands" the calling process, although I am not sure. Note, that I have tested the simple DLL with a Delphi application and everything is OK.


Have you experienced similar problems with other languages (e.g. VB/VC++ DLL form)?
Does anyone have any idea why this might occur and it could be solved?


Any help is grealy appreciated.


Thank you for your time,


Stelios


// ---- code for NativeCaller.java ----

package delphitest;

...

// shows a Windows alert message box

public native void showMessage(String message);

// shows a Delphi form

public native void showForm(String caption);

...



// ---- code for Delphi project -----

library NativeCaller;



// the exported methods are here

uses

Main in 'Main.pas' {Form1};

// the exported methods

exports

Java_delphitest_NativeCaller_showMessage,

Java_delphitest_NativeCaller_showForm;



begin

end.


// --- code for Delphi form ----

unit Main;

// import the JNI.pas which contains the Java2Delphi bridge code

uses

JNI, Windows,...;

...

// forward declarations

procedure Java_delphitest_NativeCaller_showMessage(PEnv: PJNIEnv; Obj: JObject; Arg1: JString); stdcall; export;

procedure Java_delphitest_NativeCaller_showForm(PEnv: PJNIEnv; Obj: JObject; Arg1: JString); stdcall; export;

...

// shows a Win alert dialog, works very well

procedure Java_delphitest_NativeCaller_showMessage(PEnv: PJNIEnv; Obj: JObject; Arg1: JString); stdcall; export;

begin

MessageDlg('Hello!', mtWarning, mbOKCancel, 0);

end;

...

// shows the form, the form is displayed "frozen"

procedure Java_delphitest_NativeCaller_showForm(PEnv: PJNIEnv; Obj: JObject; Arg1: JString); stdcall; export;

begin

temp := TForm1.Create(nil);

temp.Show();

temp.Update();

end;

   <<Less

Re: Calling Delphi forms in DLL from Java

Posted By:   Laurent_Mihalkovic  
Posted On:   Tuesday, June 11, 2002 10:16 PM

to get things to work, you may will have to create yourn own thread inside the bridging code that will contain its own message pump to dispatch the native windows messages. This is not straight forward code to write, and you will have the additional problem of having the dialog to show independently from the java window (not even a child window) until you figure a way of hacking the window hierarchy.

cheers,
lm.

About | Sitemap | Contact