nageswaragunupudi wrote:Please use this function. This is very fast.
function FW_DbfRenameField( cDbf, cField, cReplace )
聽 聽local lSuccess := .f.
聽 聽local hFile, nHeaderSize, nAt
聽 聽local cBuf 聽 聽 := Space( 32 )
聽 聽if !File( cDbf )
聽 聽 聽 ? cDbf + " not found"
聽 聽 聽 return .f.
聽 聽endif
聽 聽if Empty( cField ) .or. Empty( cReplace ) .or. ;
聽 聽 聽 Len( cField ) > 10 .or. Len( cReplace ) > 10
聽 聽 聽 ? "Invalid field names"
聽 聽 聽 return .f.
聽 聽endif
聽 聽cField 聽 聽 聽 聽 聽 聽:= PADR( UPPER( cField ), 聽 11, CHR( 0 ) )
聽 聽cReplace 聽 聽 聽 聽 聽:= PADR( UPPER( cReplace ), 11, CHR( 0 ) )
聽 聽if cField == cReplace
聽 聽 聽 ? "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 )
聽 聽 聽 聽 聽 聽 nAt 聽 聽 聽:= At( cField, cBuf )
聽 聽 聽 聽 聽 聽 if nAt > 0 .and. At( cReplace, cBuf ) == 0
聽 聽 聽 聽 聽 聽 聽 聽FSeek( hFile, nAt - 1, FS_SET )
聽 聽 聽 聽 聽 聽 聽 聽if FWrite( hFile, cReplace, 11 ) == 11
聽 聽 聽 聽 聽 聽 聽 聽 聽 lSuccess := .t.
聽 聽 聽 聽 聽 聽 聽 聽endif
聽 聽 聽 聽 聽 聽 endif
聽 聽 聽 聽 聽endif
聽 聽 聽 endif
聽 聽 聽 Fclose( hFile )
聽 聽else
聽 聽 聽 ? "Can not open " + cDbf + " exclusively"
聽 聽endif
return lSuccess
Mr. Rao, thanks!
I got this error
Application
===========
Path and name: C:\fwh1705\samples\testconv.exe (32 bits)
Size: 3,738,112 bytes
Compiler version: Harbour 3.2.0dev (r1801051438)
FiveWin version: FWH 17.05
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.1, Build 7601 Service Pack 1
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 11/04/18, 10:04:26
Error description: Error BASE/1003 Variable does not exist: FO_READWRITE
Stack Calls
===========
Called from: testconv.prg => FW_DBFRENAMEFIELD( 48 )
Called from: testconv.prg => MAIN( 16 )
System
======
CPU type: Intel(R) Core(TM) i3-4160T CPU @ 3.10GHz 3092 Mhz
Hardware memory: 8110 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Windows total applications running: 5
1 ,
2 , C:\fwh1705\samples\testconv.exe
3 DDE Server Window, C:\Windows\syswow64\OLE32.DLL
4 GDI+ Window, C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.24234_none_5c05ea59a00ef5
5 MCI command handling window, C:\Windows\system32\WINMM.DLL
Variables in use
================
Procedure Type Value
==========================
FW_DBFRENAMEFIELD
Param 1: O Class: ERROR
MAIN
Param 1: C "MXCTACLI.DBF"
Param 2: C "CODCLI "
Param 3: C "CUSTCODE "
Local 1: L .F.
Local 2: U
Local 3: U
Local 4: U
Local 5: C " "
Local 6: S
Local 7: U
Local 8: C "MXCTACLI.DBF"
Local 9: U
Local 10: U
Local 11: U
Linked RDDs
===========
DBF
DBFFPT
DBFBLOB
DBFNTX
DataBases in use
================
Classes in use:
===============
1 ERROR
2 HBCLASS
3 HBOBJECT
4 TWINDOW
5 TBRUSH
6 TFONT
7 TREG32
8 TSTRUCT
Memory Analysis
===============
360 Static variables
Dynamic memory consume:
Actual Value: 524288 bytes
Highest Value: 524288 bytes
Below my code
#include "FiveWin.ch"
static oWnd
//----------------------------------------------------------------------------//
function Main()
聽 聽LOCAL cDbf 聽 :="MXCTACLI.DBF"
聽 聽LOCAL cField :="CODCLI"
聽 聽LOCAL cReplace :="CUSTCODE"
聽 聽
聽 聽SET _3DLOOK ON
聽 聽DEFINE WINDOW oWnd TITLE "Storing Menus at DBFs" ;
聽 聽
聽 聽FW_DbfRenameField( cDbf, cField, cReplace )
聽 聽SET MESSAGE OF oWnd TO "Storing menus at a DBF"
聽 聽ACTIVATE WINDOW oWnd
return nil
function FW_DbfRenameField( cDbf, cField, cReplace )
聽 聽local lSuccess := .f.
聽 聽local hFile, nHeaderSize, nAt
聽 聽local cBuf 聽 聽 := Space( 32 )
聽 聽if !File( cDbf )
聽 聽 聽 ? cDbf + " not found"
聽 聽 聽 return .f.
聽 聽endif
聽 聽if Empty( cField ) .or. Empty( cReplace ) .or. ;
聽 聽 聽 Len( cField ) > 10 .or. Len( cReplace ) > 10
聽 聽 聽 ? "Invalid field names"
聽 聽 聽 return .f.
聽 聽endif
聽 聽cField 聽 聽 聽 聽 聽 聽:= PADR( UPPER( cField ), 聽 11, CHR( 0 ) )
聽 聽cReplace 聽 聽 聽 聽 聽:= PADR( UPPER( cReplace ), 11, CHR( 0 ) )
聽 聽if cField == cReplace
聽 聽 聽 ? "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 )
聽 聽 聽 聽 聽 聽 nAt 聽 聽 聽:= At( cField, cBuf )
聽 聽 聽 聽 聽 聽 if nAt > 0 .and. At( cReplace, cBuf ) == 0
聽 聽 聽 聽 聽 聽 聽 聽FSeek( hFile, nAt - 1, FS_SET )
聽 聽 聽 聽 聽 聽 聽 聽if FWrite( hFile, cReplace, 11 ) == 11
聽 聽 聽 聽 聽 聽 聽 聽 聽 lSuccess := .t.
聽 聽 聽 聽 聽 聽 聽 聽endif
聽 聽 聽 聽 聽 聽 endif
聽 聽 聽 聽 聽endif
聽 聽 聽 endif
聽 聽 聽 Fclose( hFile )
聽 聽else
聽 聽 聽 ? "Can not open " + cDbf + " exclusively"
聽 聽endif
return lSuccess
function AppExit()
聽 聽oWnd:End()
return nil