Delete BTNBMP and create new -> no ACTION ?

Delete BTNBMP and create new -> no ACTION ?

Postby Jimmy » Wed May 17, 2023 3:48 pm

hi,

i have Button for each Drive
Image
when add / remove USB Drive i want to "End()" BTNBMP and create new depend on Drive Letter
Code: Select all  Expand view
oMain:bOnDeviceChange := { | o, w, l | OnDeviceChange( o, w, l ), oMain:Refresh() }

this "seem" to work but there is no ACTION any more ... :shock:

Code: Select all  Expand view
PROCEDURE DriveButton()
LOCAL aDrives   := FillDriveArray()
LOCAL ii, iMax
LOCAL oBtn
LOCAL acItem, cDrive
LOCAL acBitmaps, cBitmap
LOCAL acType
LOCAL nFirstUSB
LOCAL aBlocks, bBlock, cBlock
LOCAL nWidth := oMain:nWidth

   IF ! EMPTY(aBtnDrives)
      iMax := LEN(aBtnDrives)
      FOR ii := iMax TO 1 STEP -1
         oBtn := aBtnDrives[ii]
         oBtn:End()
         A_Remove(aBtnDrives,ii)
      NEXT

      aBtnDrives := {}
   ENDIF

   acItem := aDrives[ 1 ]
   acBitmaps := aDrives[ 2 ]
   acType := aDrives[ 3 ]
   nFirstUSB := aDrives[ 4 ]

   aBtnDrives := {}

   iMax := LEN( acItem )

   nGridFocus := 1
   ii := 1
   FOR ii := 1 TO iMax
      cDrive := SUBSTR( acItem[ ii ], 1, 2 ) + ´\´
      cBitmap := acBitmaps[ ii ]

      @ 40, ( ii - 1 ) * ( ( nBB * 2 ) + 2 ) BTNBMP oBtn SIZE nBB * 2, nBB PIXEL OF oMain ;
              PROMPT cDrive LEFT ;
              RESNAME cBitmap ;
              FONT oFontDefault COLOR BFcolor, BGcolor

      oBtn:bClrGrad := bGradient
      bBlock := DoDetachLocal( cDrive )
      oBtn:bAction := bBlock

      __ChangeStyleWindow( oBtn:hWnd, WS_TABSTOP,, .F. )

      AADD( aBtnDrives, oBtn )
   NEXT

   nGridFocus := 2
   ii := 1
   FOR ii := 1 TO iMax
      cDrive := SUBSTR( acItem[ ii ], 1, 2 ) + ´\´
      cBitmap := acBitmaps[ ii ]

      @ 40, ( nWidth / 2 ) +( ( ii - 1 ) * ( ( nBB * 2 ) + 2 )) BTNBMP oBtn SIZE nBB * 2, nBB PIXEL OF oMain ;
              PROMPT cDrive LEFT ;
              RESNAME cBitmap ;
              FONT oFontDefault COLOR BFcolor, BGcolor

      oBtn:bClrGrad := bGradient
      bBlock := DoDetachLocal( cDrive )
      oBtn:bAction := bBlock

      __ChangeStyleWindow( oBtn:hWnd, WS_TABSTOP,, .F. )

      AADD( aBtnDrives, oBtn )
   NEXT

   nGridFocus := 1
RETURN


Code: Select all  Expand view
STATIC FUNCTION DoDetachLocal( cDrive )
LOCAL cBlock := "{|o| DoDoDo('" + cDrive + "') }"
LOCAL bBlock
   bBlock := &cBlock
RETURN bBlock

PROCEDURE DoDoDo( cDrive )
   IF nGridFocus = 1
      oExpl_Left:DoNextFolder( cDrive )
   ELSE
      oExpl_Right:DoNextFolder( cDrive )
   ENDIF
RETURN
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Delete BTNBMP and create new -> no ACTION ?

Postby Jimmy » Wed May 17, 2023 5:55 pm

hi

here is a Sample
Code: Select all  Expand view
#include "FiveWin.ch"
#xtranslate END WINDOW          => // END WINDOW
STATIC nBB           := 30
STATIC aBtnDrives    := {}
MEMVAR oMain

PROCEDURE Main()
LOCAL oBtn
PRIVATE oMain

   DEFINE WINDOW oMain FROM 0, 0 TO 600, 800 PIXEL TITLE "FiveWin DriveButton() Demo"

      DriveButton()

      @ 080, 010 BUTTON oBtn PROMPT FWString( "new Button" ) SIZE 260, 50 PIXEL ACTION DriveButton() OF oMain

   END WINDOW
   ACTIVATE WINDOW oMain CENTER
RETURN

PROCEDURE DriveButton()
LOCAL aDrives := aDrives()
LOCAL ii, iMax
LOCAL oBtn, bBlock
LOCAL cDrive

   IF ! EMPTY(aBtnDrives)
      iMax := LEN(aBtnDrives)
      FOR ii := iMax TO 1 STEP -1
         oBtn := aBtnDrives[ii]
         oBtn:Destroy()

         ADEL(aBtnDrives,ii)
         ASIZE(aBtnDrives,LEN(aBtnDrives)-1)
         SysRefresh()
      NEXT
   ENDIF

   iMax := LEN(aDrives)
   ii := 1
   FOR ii := 1 TO iMax
      cDrive := aDrives[ii] + ´\´

      @ 40, ( ii - 1 ) * ( ( nBB * 2 ) + 2 ) BTNBMP oBtn SIZE nBB * 2, nBB PIXEL OF oMain ;
              PROMPT cDrive LEFT

      bBlock := DetachBlock(ii)
      oBtn:bAction  := bBlock

      * bBlock := DoDetachLocal( cDrive )
      * oBtn:bAction := bBlock

      __ChangeStyleWindow( oBtn:hWnd, WS_TABSTOP,, .F. )

      AADD( aBtnDrives, oBtn )
      INVALIDATERECT( oBtn:hWnd )
   NEXT

   INVALIDATERECT( oMain:hWnd )

RETURN

STATIC FUNCTION DetachBlock( ii )
LOCAL cBlock := "{|| msgInfo(" + STR( ii ) + ")}"
LOCAL bBlock
   bBlock := &cBlock
RETURN bBlock

when start you can press any "Drive" Button and get a MsgInfo()

than press "new Button" and try "Drive" Button ... they do not "react" any more ... :shock:
what i´m doing wrong :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Delete BTNBMP and create new -> no ACTION ?

Postby karinha » Wed May 17, 2023 6:59 pm

Hy Jimmy. Look this:

Code: Select all  Expand view

#include "FiveWin.ch"

#Define CLR_MSPURPLE   nRGB( 0,   120, 215 )
#Define CLR_MSRED      nRGB( 232,  17,  35 )
#Define CLR_MSGRAY     nRGB( 229, 229, 229 )
#Define CLR_LGRAY      nRGB( 230, 230, 230 )
#Define CLR_MAGENTA2   nRGB( 239, 222, 222 )

#xtranslate END WINDOW          => // END WINDOW

STATIC nBB        := 30
STATIC aBtnDrives := {}

STATIC oWnd

FUNCTION Main()

   LOCAL oBtn, oBtnExit, cTitle := "FiveWin DriveButton() Demo"

   SkinButtons()

   DEFINE WINDOW oWnd FROM 0, 0 TO 600, 800 PIXEL TITLE cTitle               ;
      COLOR CLR_BLACK, CLR_MSPURPLE

   @ 080, 050 BUTTON oBtn PROMPT FWString( "New Button" ) SIZE 100, 50 PIXEL ;
      ACTION( DriveButton( oWnd ) ) OF oWnd

   @ 080, 180 BUTTON oBtnExit PROMPT FWString( "Exit" ) SIZE  80, 50 PIXEL   ;
      ACTION( oWnd:End() ) OF oWnd

   // END WINDOW  //
   ACTIVATE WINDOW oWnd CENTERED ON INIT( DriveButton( oWnd ) )

RETURN NIL

FUNCTION DriveButton( oWnd )

   LOCAL aDrives := aDrives()
   LOCAL ii, iMax, oBtn, bBlock, cDrive, oFont

   DEFINE FONT oFont  NAME "Ms Sans Serif"  SIZE 00, -14 BOLD

   IF .NOT. Empty( aBtnDrives )

      iMax := Len( aBtnDrives )

      FOR ii := iMax TO 1 STEP -1

         SysRefresh()

         oBtn := aBtnDrives[ ii ]

         oBtn:Hide()
         oBtn:End()

         ADel( aBtnDrives, ii )

         ASize( aBtnDrives, Len( aBtnDrives ) - 1 )

      NEXT

   ENDIF

   iMax := Len( aDrives )

   ii := 1

   FOR ii := 1 TO iMax

      SysRefresh()

      cDrive := aDrives[ ii ] + "\"

      @ 40, ( ii - 1 ) * ( ( nBB * 2 ) + 2 ) BTNBMP oBtn SIZE nBB * 2, nBB ;
         PIXEL OF oWnd PROMPT cDrive LEFT COLOR CLR_BLACK, CLR_MSPURPLE    ;
         FONT oFont FLAT 2007

      /*
      oBtn:bClrGrad = {| lInvert | If( ! lInvert,                ;
         { { 0.25, RGB( 238, 236, 219 ), RGB( 238, 236, 219 ) }, ;
         { 0.75, RGB( 238, 236, 219 ), RGB( 238, 236, 219 ) } }, ;
         { { 0.25, RGB( 238, 236, 219 ), RGB( 238, 236, 219 ) }, ;
         { 0.75, RGB( 238, 236, 219 ), RGB( 238, 236, 219 ) } } ) }
      */

      WITH OBJECT oBtn
         :nClrBorder := CLR_HRED //  border color
         :bColorMap  := { || { { CLR_YELLOW, CLR_HRED } } }  // image color
      END

      oBtn:lTransparent := .T.
      oBtn:cToolTip =  { "
Button" + CRLF + "Test", "BUTTON", 1, CLR_BLACK, 14089979 }
      oBtn:SetColor( 0, )

      bBlock := DetachBlock( ii )

      oBtn:bAction := bBlock

      oBtn:lCancel := .T.

      // bBlock := DoDetachLocal( cDrive )
      // oBtn:bAction := bBlock

      __ChangeStyleWindow( oBtn:hWnd, WS_TABSTOP,, .F. )

      AAdd( aBtnDrives, oBtn )

      INVALIDATERECT( oBtn:hWnd )

   NEXT

   INVALIDATERECT( oWnd:hWnd )

RETURN NIL

STATIC FUNCTION DetachBlock( ii )

   LOCAL cBlock := "
{|| msgInfo(" + Str( ii ) + ")}"
   LOCAL bBlock

   bBlock := &cBlock

RETURN bBlock

// FIN / END


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Delete BTNBMP and create new -> no ACTION ?

Postby Jimmy » Wed May 17, 2023 8:38 pm

hi

thx for Answer.

after read in your CODE i insert
Code: Select all  Expand view
  oBtn:Hide()
   oBtn:destroy()  // => End()

now it work :)

but i see no reason "why" it does not work without oBtn:Hide() ... hm ... :?

hm ... are Button "real" Destroy :idea:

i have add to 2nd Button
Code: Select all  Expand view
  MsgInfo( LEN(oMain:aControls) )

and it does increase every time i press "new Button" ...

---

i have "overthink" my Concept to "Destroy" Control

now i create 26 x Button (A-Z) and hide() what is not need
when add/remove i do hide() all and than change

Code: Select all  Expand view
  bBlock := DoDetachLocal( cDrive )
   oBtn:bAction := bBlock
   oBtn:cCaption := cDrive
   oBtn:Show()


but i still like to know how to add/remove Control at Runtime :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 100 guests