我有个3-DES的加密程序是java的代码,我写了个函数,在jsp中可以用,但是我的delphi程序怎么调用呢?

解决方案 »

  1.   

    http://www.pacifier.com/~mmead/jni/delphi/informant/di200310kw.htmCalling Java Code from a Delphi AppIn Part 1, you saw how Delphi code could be called from a Java application using the Java Native Interface (JNI). By following certain naming conventions, and by using specific data types and structures within your native code, your Java classes can easily invoke these routines, passing parameters and results between the two. Exceptions can also be generated and handled on either side of the interface. This installment will demonstrate how Java code can be called from a Delphi application, fulfilling the bi-directional promise of JNI.The ease-of-use of Delphi and Java interactions is due to the efforts of Matthew Mead, who has produced a Pascal translation of the JNI suitable for use in Delphi. If you haven’t already, you can download the package from Matthew’s Web site (see "References" at the end of this article).
      

  2.   

    Begin Listing One — Calling the Java class{ Generate a Pascal skeleton for JNI. }
    procedure TfrmJavaD.btnGenerateClick(Sender: TObject);
    var
      Cls: JClass;
    { $IFNDEF JNIUTILS }
      MID: JMethodID;
    { $ENDIF }
      Exc: JThrowable;
      FileName: string;
      ErrMsg: string;
    begin
      try
        memOutput.Lines.Clear;
        ShowStatus('Calling generator method...');
        // Find JavaD class
        Cls := FJNIEnv.FindClass(
          'wood/keith/opentools/javad/JavaD');
        if Cls = nil then
          raise Exception.Create('Can't find class: ' +
            'wood.keith.opentools.javad.JavaD');
        // Run it
    { $IFDEF JNIUTILS }
        FileName := JNIUtils.CallMethod(FJNIEnv, Cls,
          'generateDelphiWrapper',
          'String (String, String, boolean)',
          [edtClassName.Text, edtDirectory.Text,
          chkOverwrite.Checked], True);
    { $ELSE }
        MID := FJNIEnv.GetStaticMethodID(Cls,
          'generateDelphiWrapper',
          '(Ljava/lang/String;Ljava/lang/String;Z)' +
          'Ljava/lang/String;');
        if MID = nil then
          raise Exception.Create('Can't find method: ' +
            'generateDelphiWrapper');    FileName := FJNIEnv.JStringToString(
          FJNIEnv.CallStaticObjectMethod(Cls, MID,
          [edtClassName.Text, edtDirectory.Text,
          chkOverwrite.Checked]));
    { $ENDIF }
        // Check for exception.
        Exc := FJNIEnv.ExceptionOccurred;
        if Exc <> nil then
        begin
          // Clear the exception so we
          // can call other methods.
          FJNIEnv.ExceptionClear;
          // Find out about the exception -
          // its class and message.
    { $IFDEF JNIUTILS }
          Cls := JNIUtils.CallObjectMethod(
            FJNIEnv, Exc, 'getClass', 'Class()', []);
          ErrMsg := JNIUtils.CallMethod(
            FJNIEnv, Cls, 'getName', 'String()', []) +
            #13 + JNIUtils.CallMethod(
            FJNIEnv, Exc, 'getMessage', 'String()', []);
    { $ELSE }
          MID := FJNIEnv.GetMethodID(
            FJNIEnv.GetObjectClass(Exc),
            'getClass', '()Ljava/lang/Class;');
          if MID = nil then
            raise Exception.Create(
              'Can't find method: getClass');
          Cls := FJNIEnv.CallObjectMethod(Exc, MID, []);
          MID := FJNIEnv.GetMethodID(
            FJNIEnv.GetObjectClass(Cls),
            'getName', '()Ljava/lang/String;');
          if MID = nil then
            raise Exception.Create(
              'Can't find method: getName');
          ErrMsg := FJNIEnv.JStringToString(
            FJNIEnv.CallObjectMethod(Cls, MID, []));
          MID := FJNIEnv.GetMethodID(
            FJNIEnv.GetObjectClass(Exc),
              'getMessage', '()Ljava/lang/String;');
          if MID = nil then
            raise Exception.Create(
              'Can't find method: getMessage');
          ErrMsg := ErrMsg + #13 +
            FJNIEnv.JStringToString(
            FJNIEnv.CallObjectMethod(Exc, MID, []));
    { $ENDIF }
          raise Exception.Create(
            'A Java exception occurred'#13 + ErrMsg);
        end;
        // Load the generated file.
        memOutput.Lines.LoadFromFile(FileName);
        ShowStatus('Done');
      except
        on E: Exception do begin
          ShowStatus('Error');
          MessageDlg('Error: ' + E.Message,
            mtError, [mbOK], 0);
        end;
      end;
    end;
      

  3.   

    http://www.veoda.com/search/click/smartframe.cgi?http://www.pacifier.com/~mmead/borland/borcon2001