procedure TForm1.Button1Click(Sender: TObject);
var
MyDbf: TDbf;
fd: TFieldDef;
i: Integer;
begin
MyDbf := TDbf.Create(nil);
try
MyDbf.FilepathFull := ExtractFilePath(Application.ExeName);
// MyDbf.FilePathFull := 'C:\PROJEKTE\PASCAL\DBA\DATA' + DirectorySeparator;
(* Wir want to create an compatible DBASE4 Table *)
MyDbf.TableLevel := 4;
MyDbf.Exclusive := true;
DeleteFile('testpasc.dbf');
MyDbf.TableName := 'testpasc.dbf';
(* For this wie need the Unit DB *)
with MyDbf.FieldDefs do
begin // Here are my own-named DBASE-Fieldtypes
Add('ID', ftInteger, 3, true); // N 3,0 NoIdx
Add('NAME', ftString, 20, true); // C 2 NoIdx
Add('ZAHL_BYTE', ftSmallInt, 3, true); // N 3 NoIdx
Add('ZAHL_INT', ftInteger, 6, true); // N 6 NoIdx
// Method #1
Add('ZAHL_FLOAT', ftFloat, 10, true); // G 10,3 NoIdx
// Method #2
with AddFieldDef do begin
Name := 'ZAHL_FLOAT2';
Datatype := ftFloat;
Size := 10;
Precision := 4;
end;
// Method #3
Add('ZAHL_FLOAT3', ftFloat, 10, true);
fd := Items[Count-1];
fd.Precision := 4;
// Method #4
Add('ZAHL_FLOAT4', ftFloat, 0, true); // G 10,3 NoIdx
end; (* of with MyDbf.FieldDefs *)
MyDbf.CreateTable;
MyDbf.Open;
for i:=0 to MyDbf.FieldCount-1 do
Memo1.Lines.Add(MyDbf.fields[i].FieldName);
MyDbf.AddIndex('id', 'ID', [ixPrimary, ixUnique]);
(* We fill the first Record *)
MyDbf.Append; // Create an Record
MyDbf.FieldByName('ID').AsInteger := 1;
MyDbf.FieldByName('NAME').AsString := 'Jesus Christ';
MyDbf.FieldByName('ZAHL_BYTE').AsInteger := 255;
MyDbf.FieldByName('ZAHL_INT').AsInteger := 32767;
MyDbf.FieldByName('ZAHL_FLOAT').AsFloat := 3.141592;
MyDbf.FieldByName('ZAHL_FLOAT2').AsFloat := 3.141592;
MyDbf.FieldByName('ZAHL_FLOAT3').AsFloat := 3.141592;
MyDbf.FieldByName('ZAHL_FLOAT4').AsFloat := 3.141592;
MyDbf.Post; // Important for Store of the Record and Continuing
finally
MyDbf.Free;
end; (* of try-finally *)
end; (* of procedure TForm1.DBF_Datei_Neu *)