FWH Logic with method's (Xbrowse ToDbf)

FWH Logic with method's (Xbrowse ToDbf)

Postby Marc Venken » Tue Dec 06, 2016 11:45 pm

I'm looking a little deeper in the system's of FWH.

As example (I want to learn more about all the options from Xbrowse)

I see lots of Methods like this in the source files :


METHOD ToDbf( cFile, bProgress, aCols, lPrompt )

and a corresponding method function like below.

So, It is correct that I can use this to find ALL options that are not reported in the Wiki files ?

If I could read these functions, The use would be something like this (Not tested, just for the idea)

oBrw:ToDbf(MyDbf,???,aCols,???)

Could someone explain this way of working i little more ?

Thanks
Marc


Code: Select all  Expand view

METHOD ToDbf( cFile, bProgress, aCols, lPrompt ) CLASS TXBrowse

   local aStruct  := {}
   local nKeyNo   := ::KeyNo
   local nRowPos  := ::nRowSel
   local n, uVal, c, oCol, nCols
   local nSelect

   if ::nLen < 1
      return nil
   endif

   DEFAULT lPrompt := .f.

   if aCols == nil
      aCols    := ::GetVisibleCols()
   else
      AEval( aCols, { |u,i| aCols[ i ] := ::oCol[ u ] } )
   endif

   ::GoTop()
   nCols       := Len( aCols )

   for each oCol in aCols
      uVal     := oCol:Value
      AAdd( aStruct, { Upper( PadR( oCol:cHeader, 10 ) ), oCol:cDataType, oCol:nDataLen, oCol:nDataDec } )
      if Empty( oCol:cHeader )
         ATail( aStruct )[ 1 ]   := "COL" + StrZero( oCol:nCreationOrder, 2 )
      endif
      if Empty( c := oCol:cDataType ) .or. !( c $ 'DLMNT' )
         ATail( aStruct )[ 2 ]   := c := If( uVal == nil, 'C', ValType( uVal ) )
      endif
      if Empty( oCol:nDataLen ) .or. c $ "DTLM"
         ATail( aStruct )[ 3 ]   := HB_DeCode( c, 'C', 40, 'D', 8, 'T', 8, 'L', 1, 'N', 14, 10 )
      endif
      if c == 'N'
         if oCol:nDataDec == nil
            ATail( aStruct )[ 4 ]   := 0
         endif
      else
         ATail( aStruct )[ 4 ]   := 0
      endif

   next

   if lPrompt
      XBROWSER aStruct TITLE cFile + ":STRUCTURE" FASTEDIT ;
         SETUP (oBrw:cEditPictures := { '@!', '!', '99','99' } )
   endif

   nSelect  := Select()

   DBCREATE( cFile, aStruct )

   if bProgress == nil
      if ::oWnd:oMsgBar == nil
         bProgress := { || nil }
      else
         bProgress := { | n, t | ::oWnd:SetMsg( FWString( "To DBF" ) + " : " + ;
                                 Ltrim( Str( n ) ) + "/" + Ltrim( Str( t ) ) ) }
      endif
   endif

   Eval( bProgress, 0, ::nLen )

   USE (cFile) NEW ALIAS XBRTODBF EXCLUSIVE
   REPEAT

      XBRTODBF->( DbAppend() )
      for n := 1 to nCols
         C     := aStruct[ n ][ 2 ] // datatype
         uVal  := aCols[ n ]:Value
         if ! Empty( uVal )
            if c == 'C'
               if ValType( uVal ) != 'C'
                  uVal     := cValToChar( uVal )
               endif
            elseif ValType( uVal ) == 'C'
               uVal  := uCharToVal( uVal, c )
            endif
            TRY
               XBRTODBF->( FieldPut( n, aCols[ n ]:Value ) )
            CATCH
               // datatype mismatch or data len exceeds
            END
         endif
      next
      Eval( bProgress, XBRTODBF->( RecNo() ), ::nLen )

   UNTIL ::Skip( 1 ) == 0
   Eval( bProgress, XBRTODBF->( LASTREC() ), XBRTODBF->( LASTREC() ) )
   CLOSE XBRTODBF

   ::KeyNo     := nKeyNo
   ::nRowSel   := nRowPos
   ::Refresh()

   if lPrompt .and. MsgYesNo( If( FWSetLanguage() == 2, "¿ ", "" ) + ;
                              FWString( "View" ) + " " + cFile + " ?",;
                              FWString( "Please select" ) )
      XBrowse( cFile )
   endif

   ::SetFocus()

return nil

 
Last edited by Marc Venken on Sun Dec 18, 2016 9:34 am, edited 1 time in total.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FWH Logic with method's from originale source

Postby Antonio Linares » Wed Dec 07, 2016 4:37 pm

Marc,

> So, It is correct that I can use this to find ALL options that are not reported in the Wiki files ?

yes

oBrw:ToDbf( cFile, bProgress, aCols, lPrompt )

where bProgress is an optional codeblock to evaluate as the DBF is built. lPrompt is a logical value to
automatically show a browse of the generated cFile
regards, saludos

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

Re: FWH Logic with method's (Xbrowse ToDbf)

Postby Marc Venken » Sun Dec 18, 2016 10:31 am

Are these functions not listed in the WIKI ?

FW_SaveArrayToDBF( cList, oBrw:aDeleted )

Or where to find them ?

This is for saving data into a existing dbf as I try to see in the samples.

I do need to create a dbf from the array. Best from the Xbrowse
with this function.

oBrw:ToDbf( cFile, bProgress, aCols, lPrompt )

Xbrowse with array of fields like aFields

DEFINE BUTTON OF oBar PROMPT "ToDbf" ACTION ( oBrw:ToDbf( "Test.dbf" ,, aFields, .f. ))

and maybe also from a sql record set afther opening online database?

DEFINE BUTTON OF oBar PROMPT "ToDbf" ACTION ( oBrw:ToDbf( "Test.dbf" ,, oRs, .f. ))
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: FWH Logic with method's (Xbrowse ToDbf)

Postby nageswaragunupudi » Mon Dec 19, 2016 10:25 am

XBrowse METHOD ToDBF( cFile, [bProgress], [aCols], [lPrompt] ) --> NIL

The datasource of the xbrowse can be anything, i.e, DBF, TDatabase, RecordSet, Array, or whatever. Purpose of this method is to save the contents of the browse as dbf.

Parameters:

1. cFile: DBF file name, with extension. A new dbf file with this name is created. If a file with that name exists, attempt is made to overwrite. Failure to overwrite resuls in runtime error. Programmer needs to ensure that a file with that name does not exist or is not open.

2. bProgress: Optional. If specified can be used to display progress. In most cases this is not required since writing is fast.

3. aCols: Optional. By default all Visible columns in the order of their visibility are written. User can hide columns not required and rearrange the columns in the order the wants. If the programmer wants to control the columns to be written, he can specify an array of columns. The array can contain nCreationOrders or HeaderNames or column objects.

4. lPrompt [Optional] Default FALSE. If lPrompt is TRUE,

(a) User is presented with a browse of dbf structure to be created. User can edit the structure before writing. By default, xbrowses uses column headers as field names. If the programmer plans to use this method, he should specify headers which are suitable to be used as field names of dbf. If not editing structure with this option helps.

(b) After writing, user will be presented with an option to view the saved DBF in browse.


function FW_ArrayToDBF( aData, cFieldList, bProgress )
source: database.prg

Purpose of the function is to append the contents of array aData at the end of Alias that is already opened in the current workarea.

Parameters:
1) aData: 2-Dimentional array
2) cFieldList [optional] By default, contents of the array are copied into fiedls in the order of the fields. If a list of fields is provided the contents are copied into the fields specified in the list. It is the responsibility of the programmer to ensure datatype compatibility with the destination fields.
3) bProgress: Optional

From the above you can see that the syntax you used for the button actions are not correct. You may revise the usage on the basis of the above explanation
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FWH Logic with method's (Xbrowse ToDbf)

Postby Marc Venken » Wed Dec 21, 2016 8:25 am

Thanks for the full explanation.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 86 guests