Page 1 of 1

From Delphi to C++

PostPosted: Fri Feb 10, 2017 5:29 am
by Lena
Hi.
Can somebody translate this code from pascal to C++ Builder:

https://blog.grijjy.com/2017/01/31/rece ... ignId=6687

Thanks!

Re: From Delphi to C++

PostPosted: Fri Feb 10, 2017 12:51 pm
by rlebeau
Something like this:

Code: Select all
class TgoRemotePushReceiver : public TObject
{
public:
    __fastcall TgoRemotePushReceiver(const UnicodeString AGCMAppId);
    __fastcall ~TgoRemotePushReceiver();
public:
    __property String DeviceToken = {read=FDeviceToken};
    __property int Number = {read=GetNumber, write=SetNumber};
};

class TgoRemoteNotificationMessage : public TMessageBase
{
public:
    __fastcall TgoRemoteNotificationMessage(const String ADataKey, const String AJson, const bool AActivated);
    __property String DataKey = {read=FDataKey};
    __property String Json = {read=FJson};
 
    /* Whether message is activated by the user (tapping in it) */
    __property bool Activated = {read=FActivated};
};

class TgoDeviceTokenChangeMessage : public TMessageBase
{
private:
    String FDeviceToken;
public:
    __fastcall TgoDeviceTokenChangeMessage(const String ADeviceToken);
    __property String DeviceToken = {read=FDeviceToken};
};


Code: Select all
RemotePushReceiver = new TgrRemotePushReceiver(MyAndroidApiKey);


Code: Select all
TMessageManager::DefaultManager->SubscribeToMessage(__classid(TgoRemoteNotificationMessage), &RemoteNotificationHandler);

...

void __fastcall TMyClass::RemoteNotificationHandler(const TObject* Sender, const TMessageBase* Msg)
{
    const TgrRemoteNotificationMessage *RemoteNotificationMessage = static_cast<const TgoRemoteNotificationMessage*>(Msg);

    /* The user tapped this push notification, which resulted in the bringing the app to the foreground? */
    if (RemoteNotificationMessage->Activated)
    {
        TgoBsonDocument *Doc = TgrBsonDocument::Parse(RemoteNotificationMessage->Json);
    }
}


Code: Select all
TMessageManager::DefaultManager->SubscribeToMessage(__classid(TgoDeviceTokenChangeMessage), &DeviceTokenChangeListener);

...

void __fastcall TMyClass::DeviceTokenChangeListener(const TObject* Sender, const TMessageBase* M);
{
    const TgoDeviceTokenChangeMessage *DeviceTokenChangeMessage = static_cast<const TgoDeviceTokenChangeMessage*>(M);
    ShowMessage(L"Device Token is " + DeviceTokenChangeMessage->DeviceToken);
}

Re: From Delphi to C++

PostPosted: Sun Feb 12, 2017 5:39 am
by Lena
Thank You very much for help and support!