Mejora del ejemplo design.prg

Mejora del ejemplo design.prg

Postby mastintin » Mon Jan 09, 2012 5:06 pm

He aumentado un poco el ejemplo design.prg y ahora permite "ejecutar" el codigo generado desde el propio programa.

Code: Select all  Expand view


static function EditDialog( nRow, nCol, oDlg )

   local oMenu
   
   MENU oMenu POPUP
      MENUITEM "Title..." ACTION EditTitle( oDlg )
     
      SEPARATOR
     
      MENUITEM "Place control"
      MENU
         MENUITEM "Say"      ACTION CreateSay( oDlg )
         MENUITEM "Get"      ACTION CreateGet( oDlg )
         MENUITEM "Button"   ACTION CreateButton( oDlg )
         MENUITEM "CheckBox" ACTION CreateCheckBox( oDlg )
         MENUITEM "ListBox"  ACTION CreateListBox( oDlg )
         MENUITEM "ComboBox" ACTION CreateComboBox( oDlg )
         MENUITEM "GroupBox" ACTION CreateGroup( oDlg )
      ENDMENU
      SEPARATOR
      MENUITEM "exec code..." ACTION Exedesign( oDlg:cGenPrg())   //-----------añadido
      MENUITEM "PRG code..." ACTION MemoEdit( oDlg:cGenPrg(), "PRG code" )
      MENUITEM "RC code..." ACTION MemoEdit( oDlg:SaveToRC(), "RC code" )
      SEPARATOR
      MENUITEM "Position"
      MENU
         MENUITEM "nTop"  + Chr( 9 ) + LTrim( Str( WndTop( oDlg:hWnd ) ) )
         MENUITEM "nLeft" + Chr( 9 ) + LTrim( Str( WndLeft( oDlg:hWnd ) ) )
      ENDMENU
      MENUITEM "Size"
      MENU
         MENUITEM "nWidth"  + Chr( 9 ) + LTrim( Str( oDlg:nWidth ) )
         MENUITEM "nHeight" + Chr( 9 ) + LTrim( Str( oDlg:nHeight ) )
      ENDMENU  
   ENDMENU
   
   ACTIVATE POPUP oMenu WINDOW oDlg AT nRow, nCol // SAVE
   
return nil  

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

static function EditTitle( oWnd )

   local oDlg, oGet, cOldTitle := PadR( oWnd:cCaption, 100 )
   
   DEFINE DIALOG oDlg TITLE "Dialog title" SIZE 600, 110
   
   @ 1, 1 GET oGet VAR oWnd:cCaption OF oDlg SIZE 285, 12 ;
      ON CHANGE oWnd:SetText( AllTrim( oGet:GetText() ) )
   
   @ 2, 18 BUTTON "&Ok" OF oDlg ACTION oDlg:End()

   @ 2, 25 BUTTON "&Cancel" OF oDlg ACTION ( oWnd:SetText( cOldTitle ), oDlg:End() )
   
   ACTIVATE DIALOG oDlg CENTERED
   
return nil  

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

function Exedesign(cCode)
   local oHrb, cResult, bOldError
   
   if Empty(ccode)
      Return .f.
   endif
   
   FReOpen_Stderr( "comp.log", "w" )
   oHrb = HB_CompileFromBuf( cCode , "-n", "-Ic:\fwh\include", "-Ic:\harbour\include" )



   If !Empty( cResult := MemoRead( "comp.log" ) )
      MemoEdit( cResult )
   endif    

   if ! Empty( oHrb )
      BEGIN SEQUENCE
      bOldError = ErrorBlock( { | o | DoBreak( o ) } )
      hb_HrbRun( oHrb )
      END SEQUENCE
      ErrorBlock( bOldError )
   endif

   return nil
   
 //----------------------------------------------------------------//

static function DoBreak( oError )

   local cInfo := oError:operation, n

   if ValType( oError:Args ) == "A"
      cInfo += "   Args:" + CRLF
      for n = 1 to Len( oError:Args )
         MsgInfo( oError:Args[ n ] )
         cInfo += "[" + Str( n, 4 ) + "] = " + ValType( oError:Args[ n ] ) + ;
                   "   " + cValToChar( oError:Args[ n ] ) + CRLF
      next
   endif

   MsgStop( oError:Description + CRLF + cInfo,;
            "Script error at line: " + AllTrim( Str( ProcLine( 2 ) ) ) )

   BREAK

return nil

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

#pragma BEGINDUMP

#include <stdio.h>
#include <hbapi.h>

HB_FUNC( FREOPEN_STDERR )
{
   hb_retnl( ( HB_LONG ) freopen( hb_parc( 1 ), hb_parc( 2 ), stderr ) );
}

#pragma ENDDUMP


 
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 47 guests