可以用delphi编写以下java程序吗?

enxuqcxy  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(274)

以下是java程序:

cardReader.searchCard(slotTypes, 60, new OnCardInfoListener() {
    @Override
    public void onCardInfo(int retCode, CardInfoEntity cardInfo) {
        //Instruction
    }
    @Override
    public void onSwipeIncorrect() {
        //Instruction
    }

    @Override
    public void onMultipleCards() {
        //Instruction
    }
    });

我试着按照下面的指示去做,不知道把剩下的放在哪里:

var
cardInfo : JOnCardInfoListener;
begin
cardReader.searchCard(slotTypes,60,TJonCardInfoListener.Create???);

end;

下面是java中的类:它是我在delphi上导入的第三方库。

package com.nexgo.oaf.apiv3.device.reader;

public interface OnCardInfoListener {
  void onCardInfo(int paramInt, CardInfoEntity paramCardInfoEntity);

  void onSwipeIncorrect();

  void onMultipleCards();
}

在用java2op从.jar文件生成的桥文件中,我有以下语句:

JOnCardInfoListener = interface;//com.nexgo.oaf.apiv3.device.reader.OnCardInfoListener

JOnCardInfoListenerClass = interface(IJavaClass)
['{283DE9B4-B2F7-4BED-B90E-A2C39DAB2687}']
end;

[JavaSignature('com/nexgo/oaf/apiv3/device/reader/OnCardInfoListener')]
JOnCardInfoListener = interface(IJavaInstance)
['{E65167F4-7C28-46EA-A29F-2993A714CC93}']
procedure onCardInfo(i: Integer; cardInfoEntity: JCardInfoEntity); cdecl;
procedure onMultipleCards; cdecl;
procedure onSwipeIncorrect; cdecl;
end;
TJOnCardInfoListener = class(TJavaGenericImport<JOnCardInfoListenerClass, JOnCardInfoListener>) end;

我可以从tjoncrardinfolistener声明另一个类来重写oncardinfo方法吗?

ccgok5k5

ccgok5k51#

非常做作的例子,基于你目前提供的,但这应该给你的想法:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  // You will need to add your import unit to the uses clause here
  Androidapi.JNI.JNIBridge;

type
  TCardInfoListener = class(TJavaLocal, JOnCardInfoListener)
  public
    { JOnCardInfoListener }
    procedure onCardInfo(i: Integer; cardInfoEntity: JCardInfoEntity); cdecl;
    procedure onMultipleCards; cdecl;
    procedure onSwipeIncorrect; cdecl;
  end;

  TForm1 = class(TForm)
  private
    FListener: JOnCardInfoListener;
  public
    procedure SearchCard;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TCardInfoListener }

procedure TCardInfoListener.onCardInfo(i: Integer; cardInfoEntity: JCardInfoEntity);
begin
  // Implementation of onCardInfo goes here
end;

procedure TCardInfoListener.onMultipleCards;
begin
  // Implementation of onMultipleCards goes here
end;

procedure TCardInfoListener.onSwipeIncorrect;
begin
  // Implementation of onSwipeIncorrect goes here
end;

{ TForm1 }

procedure TForm1.SearchCard;
begin
  if FListener = nil then
    FListener := TCardInfoListener.Create;
  cardReader.searchCard(slotTypes, 60, FListener);
end;

end.

相关问题