No se si existia en Xailer, pero de no existir, igual seria bueno el incluirla, y a poder ser, mejorarla, claro...como no se si seria posible, cambiar la longitud, tipo...
Aquí dejo el código
Código: Seleccionar todo
#include "Xailer.ch"
#include "fileio.ch"
CLASS TForm1 FROM TForm
COMPONENT oButton1
METHOD CreateForm()
METHOD Button1Click( oSender )
ENDCLASS
#include "Form1.xfm"
//------------------------------------------------------------------------------
METHOD Button1Click( oSender ) CLASS TForm1
local cDbf := "C:\Xailer\Samples\DataControls\Customer.dbf" // from folder \fwh\samples\states.dbf
local cField := "FIRST"
local cReplace := "NOMBRE"
use (cDbf)
LogDebug( "Original Name: " + DBStruct()[1,1] )
use
DbfRenameField( cDbf, cField, cReplace )
use (cDbf)
LogDebug( "Change Name: " + DBStruct()[1,1] )
use
DbfRenameField( cDbf, cReplace, cField )
use (cDbf)
LogDebug( "Return Original Name: " + DBStruct()[1,1] )
use
return nil
*/
//----------------------------------------------------------------------------//
static function DbfRenameField( cDbf, cField, cReplace )
local lSuccess := .f.
local hFile, nHeaderSize, nAt
local cBuf := Space( 32 )
if !File( cDbf )
MsgInfo( cDbf + " not found" )
return .f.
endif
if Empty( cField ) .or. Empty( cReplace ) .or. ;
Len( cField ) > 10 .or. Len( cReplace ) > 10
MsgInfo( "Invalid field names" )
return .f.
endif
cField := UPPER( cField ) + CHR( 0 )
cReplace := UPPER( cReplace ) + CHR( 0 )
if cField == cReplace
MsgInfo( "Invalid field names" )
return .f.
endif
if ( hFile := FOpen( cDbf, FO_READWRITE + FO_EXCLUSIVE ) ) >= 0
if FRead( hFile, @cBuf, 32 ) == 32
nHeaderSize := BIN2I( SUBSTR( cBuf, 9, 2 ) )
if nHeaderSize > 32
cBuf := Space( nHeaderSize )
FSeek( hFile, 0, FS_SET )
FRead( hFile, @cBuf, nHeaderSize )
if ( nAt := FieldAt( cField, cBuf ) ) > 0
if FieldAt( cReplace, cBuf ) == 0
cReplace := PADR( cReplace, 11, CHR( 0 ) )
FSeek( hFile, nAt - 1, FS_SET )
if FWrite( hFile, cReplace, 11 ) == 11
lSuccess := .t.
endif
else
MsgInfo( cReplace + " exists in dbf" )
endif
else
MsgInfo( cField + " not in dbf" )
endif
endif
endif
Fclose( hFile )
else
MsgInfo( "Can not open " + cDbf + " exclusively" )
endif
return lSuccess
//----------------------------------------------------------------------------//
static function FieldAt( cField, cBuf )
local nAt := 33
local nFldLen := Len( cField )
for nAt := 33 to Len( cBuf ) - 2 STEP 32
if cField == SubStr( cBuf, nAt, nFldLen )
return nAt
endif
next
return 0
//----------------------------------------------------------------------------//
y el proyecto, también...