Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TwebBrowser event handler


This question is answered.


Permlink Replies: 5 - Last Post: Mar 11, 2016 3:21 AM Last Post By: michel achille
michel achille

Posts: 6
Registered: 3/18/12
TwebBrowser event handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 9:04 AM
good morning, in a form, I create dynamically a webbrowser :

WebBrowser1 = new TWebBrowser(Glacefronton);
if(WebBrowser1 == NULL)return ;
WebBrowser1->Visible=false;
WebBrowser1->ParentWindow= Glacefronton->Handle ;
WebBrowser1->Left= 0;
WebBrowser1->Top=0;
WebBrowser1->Width= Screen->Width*.7;
WebBrowser1->Height=Screen->Height*.7;
etc...

assign methods

WebBrowser1->OnNewWindow3 = WebBrowser1NewWindow3; I get the message ::[bcc32 Erreur] baseflip.cpp(1634): E2034 Impossible de convertir 'void (_fastcall * (_closure )(TObject *,IDispatch * &,unsigned short &,unsigned long,const WideString,const WideString))(TObject *,IDispatch * &,unsigned short &,unsigned long,const WideString,const WideString)' en 'TWebBrowserNewWindow3' .......WHY?????

WebBrowser1->OnFileDownload = WebBrowser1FileDownload; accepted by the compilator

could you tel me how to succeed in declaring dynamically the methods?

both were working in an older version of c++ builder.

.h file :
void __fastcall WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp, WordBool &Cancel,
DWORD dwFlags, const WideString bstrUrlContext, const WideString bstrUrl);

void __fastcall WebBrowser1FileDownload(TObject *ASender, WordBool ActiveDocument,
WordBool &Cancel);

.cpp file:

void __fastcall TGlacefronton::WebBrowser1FileDownload(TObject *ASender, WordBool ActiveDocument,
WordBool &Cancel)
{
int t=0;//pour test
}

void __fastcall TGlacefronton::WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp,
WordBool &Cancel, DWORD dwFlags, const WideString bstrUrlContext,
const WideString bstrUrl)
{
int t=2;//pour test
}

thanks for your help.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TwebBrowser event handler
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 12:10 PM   in response to: michel achille in response to: michel achille
michel wrote:

WebBrowser1->OnNewWindow3 = WebBrowser1NewWindow3;

I get the message

::[bcc32 Erreur] baseflip.cpp(1634): E2034 Impossible de convertir
'void (_fastcall * (_closure )(TObject *,IDispatch * &,unsigned short
&,unsigned long,const WideString,const WideString))(TObject
*,IDispatch * &,unsigned short &,unsigned long,const WideString,const
WideString)' en 'TWebBrowserNewWindow3'

.......WHY?????

Because your WebBrowser1NewWindow3() method does not have the correct signature
that the OnNewWindow3 event is expecting.

Look at the declaration of TWebBrowserNewWindow3:

typedef void __fastcall (__closure *TWebBrowserNewWindow3)(System::TObject* 
ASender, _di_IDispatch &ppDisp, System::WordBool &Cancel, unsigned dwFlags, 
const System::WideString bstrUrlContext, const System::WideString bstrUrl);


And compare that to your declaration of WebBrowser1NewWindow3():

void __fastcall WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp, 
WordBool &Cancel, DWORD dwFlags, const WideString bstrUrlContext, const WideString 
bstrUrl);


The second parameter is mismatched. The event uses _di_IDispatch&, but your
method uses IDispatch*& instead.

both were working in an older version of c++ builder.

You must have been using a really old version then. Back then, the event
was still using IDispatch*&. It was changed to _di_IDispatch& several years
ago.

--
Remy Lebeau (TeamB)
michel achille

Posts: 6
Registered: 3/18/12
Re: TwebBrowser event handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 11:46 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
michel wrote:

WebBrowser1->OnNewWindow3 = WebBrowser1NewWindow3;

I get the message

::[bcc32 Erreur] baseflip.cpp(1634): E2034 Impossible de convertir
'void (_fastcall * (_closure )(TObject *,IDispatch * &,unsigned short
&,unsigned long,const WideString,const WideString))(TObject
*,IDispatch * &,unsigned short &,unsigned long,const WideString,const
WideString)' en 'TWebBrowserNewWindow3'

.......WHY?????

Because your WebBrowser1NewWindow3() method does not have the correct signature
that the OnNewWindow3 event is expecting.

Look at the declaration of TWebBrowserNewWindow3:

typedef void __fastcall (__closure *TWebBrowserNewWindow3)(System::TObject* 
ASender, _di_IDispatch &ppDisp, System::WordBool &Cancel, unsigned dwFlags, 
const System::WideString bstrUrlContext, const System::WideString bstrUrl);


And compare that to your declaration of WebBrowser1NewWindow3():

void __fastcall WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp, 
WordBool &Cancel, DWORD dwFlags, const WideString bstrUrlContext, const WideString 
bstrUrl);


The second parameter is mismatched. The event uses _di_IDispatch&, but your
method uses IDispatch*& instead.

both were working in an older version of c++ builder.

You must have been using a really old version then. Back then, the event
was still using IDispatch*&. It was changed to _di_IDispatch& several years
ago.

--
Remy Lebeau (TeamB)
michel achille

Posts: 6
Registered: 3/18/12
Re: TwebBrowser event handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2016 12:19 AM   in response to: michel achille in response to: michel achille
michel achille wrote:
Remy Lebeau (TeamB) wrote:
michel wrote:

WebBrowser1->OnNewWindow3 = WebBrowser1NewWindow3;

I get the message

::[bcc32 Erreur] baseflip.cpp(1634): E2034 Impossible de convertir
'void (_fastcall * (_closure )(TObject *,IDispatch * &,unsigned short
&,unsigned long,const WideString,const WideString))(TObject
*,IDispatch * &,unsigned short &,unsigned long,const WideString,const
WideString)' en 'TWebBrowserNewWindow3'

.......WHY?????

Because your WebBrowser1NewWindow3() method does not have the correct signature
that the OnNewWindow3 event is expecting.

Look at the declaration of TWebBrowserNewWindow3:

typedef void __fastcall (__closure *TWebBrowserNewWindow3)(System::TObject* 
ASender, _di_IDispatch &ppDisp, System::WordBool &Cancel, unsigned dwFlags, 
const System::WideString bstrUrlContext, const System::WideString bstrUrl);


And compare that to your declaration of WebBrowser1NewWindow3():

void __fastcall WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp, 
WordBool &Cancel, DWORD dwFlags, const WideString bstrUrlContext, const WideString 
bstrUrl);


The second parameter is mismatched. The event uses _di_IDispatch&, but your
method uses IDispatch*& instead.

both were working in an older version of c++ builder.

You must have been using a really old version then. Back then, the event
was still using IDispatch*&. It was changed to _di_IDispatch& several years
ago.

--
Remy Lebeau (TeamB)


Before trying Seattle, I was using c++builder 4 .... very old version.

I've changed the declaration as you told me and now, It works ... Thank you very much for your help.

An other question:
Could you tell me, for future, were I can see the déclarations of the methods (I've had a look through .hpp but couldn't see)

If, instead of creating dynamically the webbrowser, I take it from the palette "internet" and put it on the form, when I want to write the code for the method "onnewwindow3", I click in the "object inspector" in the right method and c++ buider, automatically right the prototype like this : void __fastcall WebBrowser1NewWindow3(TObject *ASender, IDispatch *&ppDisp, WordBool &Cancel,
DWORD dwFlags, const WideString bstrUrlContext, const WideString bstrUrl);
Which seems not to be correct....... do you have an explanation?

Thanks again

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TwebBrowser event handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2016 10:14 AM   in response to: michel achille in response to: michel achille
michel wrote:

Could you tell me, for future, were I can see the déclarations of the
methods (I've had a look through .hpp but couldn't see)

TWebBrowserNewWindow3 is declared in SHDocVw.hpp.

If, instead of creating dynamically the webbrowser, I take it from the
palette "internet" and put it on the form, when I want to write the
code for the method "onnewwindow3", I click in the "object inspector"
in the right method and c++ buider, automatically right the prototype
like this :

void __fastcall WebBrowser1NewWindow3(TObject *ASender,
IDispatch *&ppDisp, WordBool &Cancel, DWORD dwFlags,
const WideString bstrUrlContext, const WideString bstrUrl);

The IDE generates event handlers based on RTTI information. In this case,
the parameter really is a reference to an IDispatch interface pointer, so
the IDE generates IDispatch*& instead of _di_IDispatch&. But, the Delphi
compiler, when generating the .hpp file, generates _di_IDispatch& instead
of IDispatch*&.

--
Remy Lebeau (TeamB)
michel achille

Posts: 6
Registered: 3/18/12
Re: TwebBrowser event handler  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 11, 2016 3:21 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
michel wrote:

Could you tell me, for future, were I can see the déclarations of the
methods (I've had a look through .hpp but couldn't see)

TWebBrowserNewWindow3 is declared in SHDocVw.hpp.

If, instead of creating dynamically the webbrowser, I take it from the
palette "internet" and put it on the form, when I want to write the
code for the method "onnewwindow3", I click in the "object inspector"
in the right method and c++ buider, automatically right the prototype
like this :

void __fastcall WebBrowser1NewWindow3(TObject *ASender,
IDispatch *&ppDisp, WordBool &Cancel, DWORD dwFlags,
const WideString bstrUrlContext, const WideString bstrUrl);

The IDE generates event handlers based on RTTI information. In this case,
the parameter really is a reference to an IDispatch interface pointer, so
the IDE generates IDispatch*& instead of _di_IDispatch&. But, the Delphi
compiler, when generating the .hpp file, generates _di_IDispatch& instead
of IDispatch*&.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02