.. Good example would be to move data from an array to db table.
No idea, why one would want to do that. Which is probably why there isn't such an example.
Consider this a bad written example:
program test2;
{$MODE OBJFPC}{$H+}
uses
Heaptrc, Dbf, db, Dbf_Common, SysUtils;
Const
DBFileName = 'mydata.dbf';
var
MyDbf : TDbf;
DataArray : Array of SmallInt;
Procedure Create_Some_Array_Data;
var
i : Integer;
begin
SetLength(DataArray, 1000000);
for i := Low(DataArray) to High(dataArray) do
DataArray[i] := Random(65536) + 1 - (65536 shr 2);
end;
procedure Do_DBF_Stuff;
var
i : Integer;
begin
MyDbf := TDbf.Create(nil);
Try
if Not FileExists(DBFileName) then
begin
Writeln('creating DB');
MyDbf.TableLevel := 7;
MyDbf.Exclusive := True;
MyDbf.TableName := DBFileName;
with MyDbf.FieldDefs do
begin
Add('Number', ftinteger, 4, true);
End;
MyDbf.CreateTable;
end
else
begin
MyDbf.TableLevel := 7;
MyDbf.Exclusive := True;
MyDbf.TableName := DBFileName;
end;
// Write some array to the table
try
Writeln('Adding Data');
MyDBF.Open;
MyDBF.Last;
for i := Low(DataArray) to High(dataArray) do
begin
MyDBF.insert;
MyDBF.Fields.Fields[0].Value:= DataArray[i];
MyDBF.Post;
end;
finally
MyDBF.Close;
end;
// Read Some Array from the table
try
Writeln('Reading Data');
MyDBF.Open;
i := MyDBF.ExactRecordCount;
SetLength(DataArray, i);
i := Low(DataArray);
MyDBF.First;
while not MyDBF.EOF do
begin
DataArray[i] := MyDBF.Fields[0].AsInteger;
MyDBF.Next;
inc(i);
end;
finally
MyDBF.Close;
end;
finally
MyDbf.Free;
end;
end;
Begin
WriteLn('Creating array Data');
Create_Some_Array_Data;
WriteLn('Perform some DBF action -> Get yourself a cuppa tea');
Do_DBF_Stuff;
WriteLn('Done');
end.
Strange, as i was able to find everything i used here from the wiki (except for one minor thing, but nothing a google search couldn't figure out). So.... what's your excuse ?
