La Web del Programador: Comunidad de Programadores
 
    Pregunta:  14206 - COMO BORRAR Y RECREAR EL ENCABEZADO DE UNA TABLA EN VPF 5.0
Autor:  César M. Varela V.
Mucho le agradecer1a quien pueda ayudarme incándome los pasos a seguir para borrar y crear de nuevo el encabezado de una tabla ".dbf" para protegerla de accesos no autorizados.

Gracias.

  Respuesta:  Antonio Estrada
La estructura del encabezado de un dbf es (según la msdn):
_________________________________________________
Byte Number Description
1 File-type identifier:
3 - .dbf without memo (FoxBase+/FoxPro/dBASE III
PLUS/dBASE IV)
131 - .dbf with memo (FoxBase+/dBASE III Plus)
139 - .dbf with memo (dBASE III)
245 - .dbf with memo (FoxPro)
2 Year of last update
3 Month of last update
4 Day of last update
5- 8 Number of records in file*
9-10 Offset to start of data**
11-12 Size of record***
13-28 Not used
29 Flag for compound index (.cdx)
0 - No .cdx file attached to the database
1 - .cdx file attached to the database
30-32 Not used
* The number of records are calculated with the following formula:
(byte#5)+(byte#6 * 256)+(byte#7 * 256 * 256)+ (byte#8 * 256 * 256 * 256)
** The offset to the start of data is computed from the beginning
of the file to the first data record. The offset is
calculated with the formula (byte#9)+(byte#10 * 256)
***The size of the records is calculated with the formula
(byte#11)+(byte#12 * 256). This number represents the sum of
the field sizes plus 1. The extra 1 is the deletion flag.
_____________________________________________
Solo tienes que copiar con funciones de bajo nivel (fopen, fread, fwrite) el encabezado en algún lugar, y copiarlo cuando quieras activar la tabla.
Este método tiene un pequeño AGUJERITO de seguridad. Si el programa se cierra sin que se desactive la cabecera (fallo inesperado, corte del suministro eléctrico, Apagado del ordenador, reset, etc), la tabla quedará visible para cualquiera... así que ten cuidado y no te confíes demasiado con este sistema