Reputation: 21
Here is the program in 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
}
});
I tried with the following instruction and don't know where to put the rest:
var
cardInfo : JOnCardInfoListener;
begin
cardReader.searchCard(slotTypes,60,TJonCardInfoListener.Create???);
end;
Here is the class in JAVA: it's a third party library that I import on delphi.
package com.nexgo.oaf.apiv3.device.reader;
public interface OnCardInfoListener {
void onCardInfo(int paramInt, CardInfoEntity paramCardInfoEntity);
void onSwipeIncorrect();
void onMultipleCards();
}
In the bridge file generated with java2op from the .jar file I have the following statement:
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;
Can I declare another class from TJonCrardInfoListener to be able to override the onCardInfo method?
Upvotes: 1
Views: 336
Reputation: 3602
Very contrived example based on what you have supplied so far, but this should give you the idea:
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.
Upvotes: 1