From Delphi to C++

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

From Delphi to C++

Postby Lena » Fri Feb 10, 2017 5:29 am

Hi.
Can somebody translate this code from pascal to C++ Builder:

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

Thanks!
Lena
BCBJ Master
BCBJ Master
 
Posts: 519
Joined: Sun Feb 06, 2011 1:28 pm

Re: From Delphi to C++

Postby rlebeau » Fri Feb 10, 2017 12:51 pm

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);
}
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1446
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: From Delphi to C++

Postby Lena » Sun Feb 12, 2017 5:39 am

Thank You very much for help and support!
Lena
BCBJ Master
BCBJ Master
 
Posts: 519
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 9 guests