FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How To Save Changes In xbrowse
Posts: 175
Joined: Tue Nov 10, 2009 10:56 AM
How To Save Changes In xbrowse
Posted: Tue May 17, 2011 11:05 AM

In the following:

include "FiveWin.ch"

include "xbrowse.ch"

static hLib

function main()

local oDlg
local oBrw
local nI
local hBitMap1, hBitMap2, hBitMap3, hBitMap4
local aArray:={}
if (Select("abc") == 0)
dbusearea(.T., Nil, "abc", Nil, Nil, .F.)
if neterr()
msginfo("File in use, please try again")
close databases
return
endif
set index to abci
else
select Select("abc")
endif

// for nI = 1 to 5
// aadd( aArray, { "", space( 255 ) } )
// next
goto top
nI = 1
do while !eof()
aadd( aArray, { "", abc->image } )
skip 1
nI = nI + 1
enddo

DEFINE DIALOG oDlg title "TEST" size 800,600

@ 0,0 XBROWSE oBrw OF oDlg columns {1,2};
Array aArray sizes {100,300} LINES CELL autocols

oBrw:nMarqueeStyle := 1
oBrw:nRowHeight := 33
// oBrw:lAdjustLastCol := .t.

oBrw:aCols[ 1 ]:nEditType := TYPE_IMAGE
oBrw:aCols[ 1 ]:lBmpStretch := .t.
oBrw:aCols[ 1 ]:lBmpTransparent := .t.
oBrw:aCols[ 1 ]:bStrImage := {|oCol, oBrw| oBrw:aRow[ 2 ] }
oBrw:aCols[ 1 ]:nDataBmpAlign := AL_CENTER
oBrw:aCols[ 1 ]:bPopUp := { |o| ColMenu( o ) }

oBrw:aCols[ 2 ]:nEditType := EDIT_BUTTON
oBrw:aCols[ 2 ]:bEditBlock := {|nRow, nCol, oCol| oCol:Value := cGetFile( ".", "Select a file" ) }

oDlg:oClient := oBrw

oBrw:CreateFromCode()

ACTIVATE DIALOG oDlg CENTERED ON INIT oDlg:Resize()

close databases
return nil


static function ColMenu( ocol )

local oPop

MENU oPop POPUP 2007
MENUITEM "Left Align" WHEN oCol:nDataBmpAlign > 0 ;
ACTION ( oCol:nDataBmpAlign:= AL_LEFT, oCol:oBrw:Refresh() )
MENUITEM "Center Align" WHEN oCol:nDataBmpAlign != AL_CENTER ;
ACTION ( oCol:nDataBmpAlign := AL_CENTER, oCol:oBrw:Refresh() )
MENUITEM "Right Align" WHEN oCol:nDataBmpAlign != AL_RIGHT ;
ACTION ( oCol:nDataBmpAlign := AL_RIGHT , oCol:oBrw:Refresh() )

  MenuAddItem( "Transparent", ,oCol:lBmpTransparent, .t., ;
     { |oItem| oCol:lBmpTransparent := !oCol:lBmpTransparent, ;
        oItem:SetCheck( oCol:lBmpTransparent ), ;
        oCol:oBrw:refresh() } )

  MenuAddItem( "Stretch", ,oCol:lBmpStretch, .t., ;
     { |oItem| oCol:lBmpStretch := !oCol:lBmpStretch, ;
        oItem:SetCheck( oCol:lBmpStretch ), ;
        oCol:oBrw:refresh() } )

ENDMENU

return oPop

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


How do I save the new file name to abc->image after I have click the second column and selected a file.

Thanks

Regards
acwoo

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How To Save Changes In xbrowse
Posted: Thu May 19, 2011 07:50 AM
A few suggestions:

#1. To display an image file name is much simpler. If the column value contains an image file name, assiginging oCol:cDataType := "F" is all that is needed to display the file name as image.
#2. You can easily browse the DBF itself and save the selected file name in the DBF as shown in the simple example given below.
Code (fw): Select all Collapse
#include 'fivewin.ch'
#include 'ord.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

static cBmpPath   := "C:\\FWH\\BITMAPS\\"    // change to your path

function Main()

   local oWnd, oBrw

   RDDSetDefault( 'DBFCDX' )

   CreateTestDBF()

   USE ABC SHARED

   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw OF oWnd ;
      COLUMNS "Image", "Image" ;
      HEADERS nil, "File" ;
      SIZES 100,200 ;
      ALIAS "ABC" CELL LINES

   WITH OBJECT oBrw
      WITH OBJECT :Image
         :cDataType        := "F"
         :nDataBmpAlign    := AL_CENTER
      END
      WITH OBJECT :File
         :nEditType        := EDIT_BUTTON
         :bEditBlock       := { |r,c,oCol| cGetFile( "*.bmp", "Select File" ) }
      END
      :CreateFromCode()
   END

   oWnd:oClient      := oBrw

   ACTIVATE WINDOW oWnd

return nil


static function CreateTestDBF()


   DbCreate( "ABC.DBF", { { "IMAGE", "C", 255, 0 } } )

   USE ABC EXCLUSIVE
   AEval( Directory( cBmpPath + "*.bmp" ), ;
          { |a| DBAppend(), ABC->Image := cBmpPath + a[ 1 ] }, ;
          1, 10 )
   CLOSE ABC

return nil


If for any reason, you insist on reading into an array and browsing the array, here is the sample to browse array and save the change the new filename in the dbf.
Code (fw): Select all Collapse
#include 'fivewin.ch'
#include 'ord.ch'
#include 'xbrowse.ch'

REQUEST DBFCDX

static cBmpPath   := "C:\\FWH\\BITMAPS\\"    // change to your path

function Main()

   local oWnd, oBrw
   local aImgFiles   := {}

   RDDSetDefault( 'DBFCDX' )

   if ! File( "ABC.DBF" )
      CreateTestDBF()
   endif

   USE ABC EXCLUSIVE
   DBEVAL( { || AAdd( aImgFiles, { RecNo(), FIELD->Image } ) } )
   GO TOP

   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw OF oWnd ;
      COLUMNS 2,2 ;
      HEADERS "Image", "File" ;
      SIZES 100,200 ;
      ARRAY aImgFiles  CELL LINES

   WITH OBJECT oBrw
      WITH OBJECT :Image
         :cDataType        := "F"
         :nDataBmpAlign    := AL_CENTER
      END
      WITH OBJECT :File
         :nEditType        := EDIT_BUTTON
         :bEditBlock       := { |r,c,oCol| cGetFile( "*.bmp", "Select File" ) }
         :bOnChange        := { |oCol| ABC->( DbGoTo( oBrw:aRow[ 1 ] ) ), ABC->Image := oCol:Value }
      END
      :CreateFromCode()
   END

   oWnd:oClient      := oBrw

   ACTIVATE WINDOW oWnd

   CLOSE ABC

return nil


static function CreateTestDBF()


   DbCreate( "ABC.DBF", { { "IMAGE", "C", 255, 0 } } )

   USE ABC EXCLUSIVE
   AEval( Directory( cBmpPath + "*.bmp" ), ;
          { |a| DBAppend(), ABC->Image := cBmpPath + a[ 1 ] }, ;
          1, 10 )
   CLOSE ABC

return nil
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion