Jump to content
Sign in to follow this  
pieomy

Need Help Java to Pascal

Recommended Posts

Posted (edited)

Hi,

 

I am trying to use Admob Rewarded Video on Delphi and found this solution https://enhance.co/documentation/native-android/rewarded-ads

 

They have java connector and I converted this Jar library with Java2OP.exe to pascal. (files attached post)

I can use basic java classes but I dont know how to use java procedures, I need help this level. can any one help me how can run this java example code on delphi.

Thank you.

 

This code working and showing rewarded video successful.

if TJEnhance.JavaClass.isRewardedAdReady=true then
begin
   TJEnhance.JavaClass.showRewardedAd(TJEnhance_RewardCallback.Wrap(TJEnhance.GetClsID));
end;

 

This is what I need to pascal

if(Enhance.isRewardedAdReady()) {
    // The ad is ready, show it
    Enhance.showRewardedAd(new RewardCallback()
    {
        // Callbacks:
        @Override
        public void onRewardGranted(int rewardValue, RewardType rewardType)
        {
            if(rewardType == RewardType.ITEM)
                writeLog("Reward granted (item)");

            else if(rewardType == RewardType.COINS)
                writeLog("Reward granted (coins), value: " + rewardValue);
        }

        @Override
        public void onRewardDeclined()
        {
            writeLog("Reward declined");
        }

        @Override
        public void onRewardUnavailable()
        {
            writeLog("Reward unavailable");
        }   
    });    
}

 

Enhance-Connector.pas about TJEnhance_RewardCallback 

  JEnhance_RewardCallbackClass = interface(IJavaClass)
    ['{CC51ED09-CBAB-43A9-A7C7-73675C3B6F55}']
  end;

  [JavaSignature('co/enhance/Enhance$RewardCallback')]
  JEnhance_RewardCallback = interface(IJavaInstance)
    ['{46C10767-D981-4109-9D96-6B9C43900405}']
    procedure onRewardDeclined; cdecl;
    procedure onRewardGranted(P1: Integer; P2: JEnhance_RewardType); cdecl;
    procedure onRewardUnavailable; cdecl;
  end;
  TJEnhance_RewardCallback = class(TJavaGenericImport<JEnhance_RewardCallbackClass, JEnhance_RewardCallback>) end;

  JEnhance_RewardTypeClass = interface(JEnumClass)
    ['{BE09443C-986F-4419-9C51-30E565A4648D}']
    {class} function _GetCOINS: JEnhance_RewardType; cdecl;
    {class} function _GetITEM: JEnhance_RewardType; cdecl;
    {class} function valueOf(P1: JString): JEnhance_RewardType; cdecl;
    {class} function values: TJavaObjectArray<JEnhance_RewardType>; cdecl;
    {class} property COINS: JEnhance_RewardType read _GetCOINS;
    {class} property ITEM: JEnhance_RewardType read _GetITEM;
  end;

  [JavaSignature('co/enhance/Enhance$RewardType')]
  JEnhance_RewardType = interface(JEnum)
    ['{CA724C25-BB1E-41D7-B106-CBA3E07077E1}']
  end;
  TJEnhance_RewardType = class(TJavaGenericImport<JEnhance_RewardTypeClass, JEnhance_RewardType>) end;

 

 

Enhance-Connector.jar

Enhance-Connector.pas

Edited by pieomy

Share this post


Link to post
6 hours ago, pieomy said:

This is what I need to pascal

You cannot do that part in Delphi; it needs to be done in Java, then you can consume it from your Delphi code.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×