FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour IE ActiveX: Posting Data
Posts: 190
Joined: Tue Mar 14, 2006 01:59 AM
IE ActiveX: Posting Data
Posted: Sat Mar 28, 2009 03: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 (fw): Select all Collapse
#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:GetProp( "Busy" ) .and. (i<40)  // Wait 20 sec. max
     SysWait(.5) ; i++
   Enddo

   oHtm:=oActiveX: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: IE ActiveX: Posting Data
Posted: Sat Mar 28, 2009 08: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
Posts: 190
Joined: Tue Mar 14, 2006 01:59 AM
Re: IE ActiveX: Posting Data
Posted: 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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 01:06 PM

Davide,

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

Ok, thanks :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 190
Joined: Tue Mar 14, 2006 01:59 AM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 02: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

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 03: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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 03:58 PM
Davide,

Here you have a working example:

test.prg
Code (fw): Select all Collapse
#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
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 04: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 (fw): Select all Collapse
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
Posts: 190
Joined: Tue Mar 14, 2006 01:59 AM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 04: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
Posts: 190
Joined: Tue Mar 14, 2006 01:59 AM
Re: IE ActiveX: Posting Data
Posted: Sun Mar 29, 2009 04:58 PM
Rick,
Rick Lipkin wrote:On Paint can still work

yes, you're right.

Thank you for helping.
Davide

Continue the discussion