How to use TCppWebBrowser on RAD 10.4

83 views Asked by At

The code below used to be perfect to C++Builder 6.0, but it is not compiling on RAD 10.4 Sydney. I am not familiar with OLE controls and its classes and methods. Can someone help me to make it work?

PogBrowser is a TCppWebBrowser.

void __fastcall TRelatPOG::ShowStream( TStream *stm )
{
    try
    {
         if( !PogBrowser->Document )
        {
             PogBrowser->Navigate(L"about:blank");
             while( PogBrowser->ReadyState != 4 )         
                Application->ProcessMessages();
        }

        IPersistStreamInit *psi;
        TStreamAdapter *sa = new   TStreamAdapter(stm,soReference);
        if( sa )
        {
            if (SUCCEEDED(PogBrowser->Document->QueryInterface(IID_IPersistStreamInit,(void **)&psi)))
            {
                psi->InitNew();
                psi->Load(*sa);// Compile error
                psi->Release();
            }
            delete sa;
        }
     }
     catch(Exception *E)
     {
         MessageDlg(String(E->ClassName()) + " ( " + E->Message + " )", mtError, TMsgDlgButtons() << mbOK, 0);
     }
 }
1

There are 1 answers

0
Remy Lebeau On

Once upon a time, TStreamAdapter used to implicitly convert to IStream*, but now it implicitly converts to _di_IStream instead (ie DelphiInterface<IStream>).

IPersistStreamInit::Save() requires IStream*, thus requires 2 conversions (TStreamAdapter -> _di_IStream -> IStream*), but C++ only allows 1 implicit conversion at a time.

So, you need to cast the TStreamAdapter to _di_IStream explicitly, which can then convert to IStream* implicitly, eg:

psi->Load(static_cast<_di_IStream>(*sa));

However, a better solution would be to let _di_IStream handle the lifetime of the TStreamAdapter to begin with, eg:

_di_IPersistStreamInit psi;
if (SUCCEEDED(PogBrowser->Document->QueryInterface(IID_IPersistStreamInit, reinterpret_cast<void**>(&psi))))
{
    _di_IStream sa(*(new TStreamAdapter(stm, soReference)));
    psi->InitNew();
    psi->Load(sa);
}