Aqui tienes un codigo para crear tu mismo las estructuras de tus archivos dbf, mediante un pequeno trozo de codigo que encontre un dia en la web...
Saludos desde
Concepcion-Chile
Código Delphi
[-]unit MakeDBF;
interface
uses
SysUtils, Classes;
TYPE
tCreateDBF = class(tObject)
private
fFileName : STRING;
dbfType : BYTE;
LangID : BYTE;
Update : array[0..2] of byte;
Rec1Pos : WORD;
RecLen : WORD;
SubRecs : tList;
isMemo : boolean;
fMemoSize : word;
public
constructor Create;
destructor Free;
procedure AddField(Name : string; fldtype : char; fldsize : byte; dec : byte);
procedure UpdateTable;
function WriteTable : boolean;
procedure ClearAll;
property FileName : string read fFileName write fFileName;
property LanguageID : byte read LangID write LangID;
property MemoSize : word read fMemoSize write fMemoSize;
end;
tDBFSubRec = class(tObject)
public
Name : array[0..10] of char;
FldType : char;
FldDisp : longint;
FldLen : byte;
FldDec : byte;
resv : array[0..13] of char;
END;
implementation
const
ValidTypes = 'BCDFGLMN';
constructor tCreateDBF.Create;
const
D : pChar = #95#12#28;
begin
fFileName := '';
dbfType := 3;
LangID := $19;
StrCopy(pChar(@update), D);
SubRecs := tList.Create;
isMemo := FALSE;
fMemoSize := 1024;
end;
destructor tCreateDBF.Free;
begin
SubRecs.Free;
end;
procedure tCreateDBF.AddField(Name : string; fldtype : char; fldsize : byte; dec : byte);
var
TmpSubRec : tDBFSubRec;
begin
fldtype := UpCase(fldtype);
if pos(fldtype, ValidTypes) = 0 then
raise Exception.Create('MAKEDBF: Invalid field type!');
TmpSubRec := tDBFSubRec.Create;
Name := UpperCase(Name);
Move(Name[1], TmpSubRec.Name, Length(Name));
TmpSubRec.FldType := fldtype;
with TmpSubRec do
begin
FldDisp := 0;
FldLen := fldSize;
FldDec := 0;
case fldType of
'D': FldLen := 8;
'M', 'G', 'B': begin
FldLen := 10;
isMemo := TRUE;
end;
'F', 'N' : FldDec := Dec;
end;
fillchar(resv, sizeof(resv), #0);
end;
SubRecs.Add(TmpSubRec);
end;
procedure tCreateDBF.UpdateTable;
var
x : integer;
NumFld : word;
RecSize : word;
TmpFld : tDBFSubRec;
begin
if isMemo then
dbfType := $8B
else
dbfType := $03;
RecSize := 0;
NumFld := SubRecs.Count;
Rec1Pos := 32 + (32*NumFld) + 1;
for x := 0 to (NumFld - 1) do
begin
TmpFld := SubRecs.Items[x];
with TmpFld do
begin
FldDisp := RecSize + 1;
RecSize := RecSize + FldLen;
end;
end;
RecSize := RecSize + 1;
RecLen := RecSize;
end;
function tCreateDBF.WriteTable : boolean;
var
OutFile : file;
x : word;
TmpFld : tDBFSubRec;
HeadEnd : char;
buf : array[0..31] of char;
memoBuf : pChar;
TmpStr : string;
begin
UpdateTable;
WriteTable := TRUE;
AssignFile(OutFile, fFileName);
{$I-}
if IOResult <> 0 then ;
ReWrite(OutFile, 1);
FillChar(Buf, sizeof(Buf), #0);
Move(dbfType, Buf[0], sizeof(dbfType));
Move(Update, Buf[1], sizeof(Update));
Move(Rec1Pos, Buf[8], sizeof(Rec1Pos));
Move(RecLen, Buf[10], sizeof(RecLen));
Move(LangID, Buf[29], sizeof(LangID));
BlockWrite(OutFile, Buf, sizeof(Buf));
for x := 0 to (SubRecs.Count - 1) do
begin
TmpFld := SubRecs.Items[x];
BlockWrite(OutFile, TmpFld.Name, sizeof(TmpFld.Name));
BlockWrite(OutFile, TmpFld.FldType, sizeof(TmpFld.FldType));
BlockWrite(OutFile, TmpFld.FldDisp, sizeof(TmpFld.FldDisp));
BlockWrite(OutFile, TmpFld.FldLen, sizeof(TmpFld.FldLen));
BlockWrite(OutFile, TmpFld.FldDec, sizeof(TmpFld.FldDec));
BlockWrite(OutFile, TmpFld.resv, sizeof(TmpFld.resv));
end;
HeadEnd := #13;
BlockWrite(OutFile, HeadEnd, 1);
CloseFile(OutFile);
if isMemo then begin
AssignFile(OutFile, ChangeFileExt(fFileName, '.DBT'));
ReWrite(OutFile, 1);
GetMem(memoBuf, fMemoSize);
FillChar(memoBuf^, fMemoSize, #0);
memoBuf[0] := #01;
memoBuf[$12] := #02;
memoBuf[$13] := #01;
memoBuf[$14] := chr(lo(fMemoSize));
memoBuf[$15] := chr(hi(fMemoSize));
TmpStr := ExtractFileName(fFileName);
TmpStr := Copy(TmpStr, 1, Length(TmpStr) - 4);
Move(TmpStr[1], memoBuf[$08], length(TmpStr));
BlockWrite(OutFile, memoBuf^, fMemoSize);
FreeMem(memoBuf, fMemoSize);
CloseFile(OutFile);
end;
if IOResult <> 0 then WriteTable := FALSE;
end;
procedure tCreateDBF.ClearAll;
begin
SubRecs.Free;
SubRecs := tList.Create;
end;
end.