Delphi and PowerBuilder Accessing Java

Java/J2EE COM Interoperability Products Page

You can also use Delphi or PowerBuilder client to access Java objects. This example is based on the VB to Java (late bound) example.

Please read through the VB example before attempting this Delphi or PowerBuilder example.

Delphi

Delphi's environment does not support the use of the "jvmName:ClassName" string when getting COM objects, so it is necessary to register a Prog ID which maps a string of the form "Part1.Part2" to the "jvmName:ClassName". The Prog ID can be anything you wish. From DOS, run the following command:

Create a new Delphi project, and on the form place a button. Double-click on the button, and go to the top of the code. Edit the Uses clause to add OleServer, ComObj:

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleServer, ComObj;

Then edit the code that is executed when the button is clicked on. This code does the same thing as the VB example:

procedure TForm1.Button1Click(Sender: TObject);
var
  Simple: Variant;
begin
  Simple := CreateOleObject('First.Simple');
  ShowMessage(Simple);

  Simple.property1 := 9874;
  ShowMessage(Simple.property1);

  Simple.property2 := now();
  ShowMessage(Simple.property2);

  Simple.method1('A String parameter');
  Simple.whoops;
end;

This is what you should see when you run the program:

You can now Run the JVM on a UNIX machine.

Delphi is developed by Borland Software Corporation.

PowerBuilder

PowerBuilder's environment supports the use of the "jvmName:ClassName" string as VB does.

This PowerBuilder example shows how to access the java.util.HashMap object. Edit the code that is executed when the button is clicked on.

Integer cResult
String mResult
OLEObject HashMap, JVersion

HashMap = CREATE OLEObject
JVersion = CREATE OLEObject

cResult = HashMap.ConnectToObject("firstjvm:java.util.HashMap")
MessageBox("Connect to java.util.HashMap", String(cResult))
cResult = JVersion.ConnectToObject("firstjvm:com.linar.jintegra.Version")
MessageBox("Connect to com.linar.jintegra.Version", String(cResult))

TRY
  MessageBox("J-Integra® Version", String(JVersion.getVersion()))
  HashMap.put("key", "value")
  mResult = HashMap.get("key")
  MessageBox("", "Used the 'key' to obtain the string '" + mResult + "' from the HashMap")
CATCH (runtimeerror e)
  MessageBox("Caught a runtimeerror", e.getMessage())
END TRY

PowerBuilder is developed by Sybase Inc.