IE ActiveX: Posting Data

IE ActiveX: Posting Data

Postby Davide » Sat Mar 28, 2009 3:49 pm

Hello all,

why does the sample below works correctly when initiated by the button click and it hangs on the "Busy" check when run by the ON INIT clause ?

Thanks,
Davide
FWH 9.03 (same behaviour on previous versions)

Code: Select all  Expand view

#include "FiveWin.ch"

***************
function Main()
***************
Local oWnd,oBtn

   DEFINE Window oWnd TITLE "Test IE"

   @ 0,0 BUTTON oBtn OF oWND ACTION Go() // This Works fine

//   ACTIVATE WINDOW oWnd                  // This Works fine

   ACTIVATE WINDOW oWnd ON INIT Go()  // This Doesn't work

   ? "Wait"
return nil


*************
Function Go()
*************
Local cHtm:="",oWnd,oActiveX,i:=0,oHtm  
Local cValue:=GetPostData("first=fivewin&last=Test IE ActiveX")

   DEFINE WINDOW oWnd TITLE "IE ActiveX"

   oActiveX = TActiveX():New( oWnd, "Shell.Explorer" )
 
   oWnd:oClient := oActiveX // To fill the entire window surface

   oActiveX:Do( "Navigate2", "https://www.fivetechsoft.com/secure/english/test.php",,,;
                 cValue,"Content-type: application/x-www-form-urlencoded"+CRLF)

   ACTIVATE WINDOW oWnd MAXIMIZED VALID ( oActiveX:End() , .t. )

   Do While oActiveX&#058;GetProp( "Busy" ) .and. (i<40)  // Wait 20 sec. max
     SysWait(.5) ; i++
   Enddo

   oHtm:=oActiveX&#058;GetProp( "Document" )    // -> Object Document

   If Empty(oHtm)
     ? "Error downloading Document"
   Else
     oHtm:=oHtm:Body                       // -> Object Body
     If Empty(oHTM)
       ? "Error downloading Body"
     Else
       cHtm := oHtm:InnerHTML              // -> html page
     Endif
   Endif

   ? cHtm  // Let's see if it works ************************

Return nil


//------------------------------------------------------------------

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HRESULT hb_oleVariantToItem( PHB_ITEM pItem, VARIANT * pVariant );

HB_FUNC( GETPOSTDATA )
{
   VARIANT vPostData = {0};
   LPSAFEARRAY psa;
   LPCTSTR cszPostData = hb_parc( 1 );
   UINT cElems = lstrlen( cszPostData );
   LPSTR pPostData;

   VariantInit( &vPostData );

   psa = SafeArrayCreateVector( VT_UI1, 0, cElems );
   if( ! psa )
   {
      hb_retnl( E_OUTOFMEMORY );
      return;
   }

   SafeArrayAccessData( psa, ( LPVOID * ) &pPostData );
   memcpy( pPostData, cszPostData, cElems );
   SafeArrayUnaccessData( psa );

   V_VT( &vPostData ) = VT_ARRAY | VT_UI1;
   V_ARRAY( &vPostData ) = psa;

   hb_oleVariantToItem( hb_param( -1, HB_IT_ANY ), &vPostData );
}

#pragma ENDDUMP  
 
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: IE ActiveX: Posting Data

Postby Antonio Linares » Sat Mar 28, 2009 8:31 pm

Davide,

When you call Go() from:

ACTIVATE WINDOW oWnd ON INIT Go()

the application main execution loop has not started yet.

As you create another window from Go(), then that one creates the main execution loop and when it gets closed, it tries to close the application and that generates the error.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: IE ActiveX: Posting Data

Postby Davide » Sun Mar 29, 2009 12:38 pm

Antonio,
Antonio Linares wrote:When you call Go() from:
ACTIVATE WINDOW oWnd ON INIT Go()
the application main execution loop has not started yet.

that was a small sample I created to show the problem. In reality my Go function is triggered by a Timer, when the main program is already up and running.
If during the Go() function the main program does not show messages, everything works as expected. If it's showing even just an MsgInfo() , the Go() function halts at oActiveX:GetProp( "Busy" ) then it crashes when I close the Window (because I've destroyed oActiveX in the VALID clause)
I'll build another sample which better match the real case.
Hi,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: IE ActiveX: Posting Data

Postby Antonio Linares » Sun Mar 29, 2009 1:06 pm

Davide,

> I'll build another sample which better match the real case.

Ok, thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: IE ActiveX: Posting Data

Postby Davide » Sun Mar 29, 2009 2:02 pm

Antonio,

>> I'll build another sample which better match the real case.

it turned out that I was doing it ON INIT even on the real prg. Everything works fine unless something else on the ON INIT after the Go() call is stopping the program's execution.

So, the question is: How can I do to run the "Go" function once, as soon as the program startups, but after the main loop has been initiated ? (I cannot use ON PAINT because it would be evaluated several times)

Thanks,
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: IE ActiveX: Posting Data

Postby Antonio Linares » Sun Mar 29, 2009 3:52 pm

Davide,

You could use a TIMER that just executes its ACTION once and then End()s itself.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: IE ActiveX: Posting Data

Postby Antonio Linares » Sun Mar 29, 2009 3:58 pm

Davide,

Here you have a working example:

test.prg
Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Test"

   ACTIVATE WINDOW oWnd ;
      ON INIT BuildTimer( oWnd )

return nil

function BuildTimer( oWnd )

   local oTmr
   
   DEFINE TIMER oTmr OF oWnd INTERVAL 1000 ACTION ( oTmr:End(), MsgInfo( "run once" ) )

   ACTIVATE TIMER oTmr

return nil
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42081
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: IE ActiveX: Posting Data

Postby Rick Lipkin » Sun Mar 29, 2009 4:23 pm

On Paint can still work .. I just define a signature value and test .. something like this which assumes go() is a static function in the same .prg :

Code: Select all  Expand view


STATIC nNUMB

nNUMB := 0

DEFINE WINDOW ..


ACTIVATE WINDOW oWND;
               ON PAINT GO()

//--------------
Static Func Go()

nNUMB++
IF nNUMB > 1
   RETURN(NIL)
ENDIF

...
...

RETURN(NIL)

 


Just a quick thought there .. I use the above in most of my 'on paint'

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: IE ActiveX: Posting Data

Postby Davide » Sun Mar 29, 2009 4:52 pm

Antonio,
Antonio Linares wrote:You could use a TIMER that just executes its ACTION once and then End()s itself.

this works fine.

THANK YOU !
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: IE ActiveX: Posting Data

Postby Davide » Sun Mar 29, 2009 4:58 pm

Rick,
Rick Lipkin wrote:On Paint can still work

yes, you're right.

Thank you for helping.
Davide
Davide
 
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests