How to use dbf tables: an example lazarus / 16-Databases ---------------------------------------------------------------------- ecitoyen · 2013-12-26 00:21 Lazarus-Free Pascal & dbf Tables As I am an user of LFP & dbf Tables, and cause i dont get enough money for donation... i am offering some lines of source about how i use dbf tables by using some procedure... Look after: 1- be sure to get dbf in the section Code: [Select]uses   Classes, SysUtils, dbf, FileUtil, LResources, Forms, Controls, Graphics,   Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm) ... ...     Dbf2: TDbf;     Dbf3: TDbf;     Dbf4: TDbf; Code: [Select] implementation { TForm1 } Procedure usedbf2(Var pathdbf: string; Var namedbf: string; Var qtdbf: integer; Var Dbf2: Tdbf); begin     Dbf2.FilePathFull := pathdbf;     Dbf2.TableLevel := 7;     Dbf2.Tablename := namedbf;     Dbf2.Exclusive := True;     Dbf2.Open;     qtdbf:=Dbf2.recordcount; end; Procedure usedbf3(Var pathdbf: string; Var namedbf: string; Var qtdbf: integer; Var Dbf3: Tdbf); begin     Dbf3.FilePathFull := pathdbf;     Dbf3.TableLevel := 7;     Dbf3.Tablename := namedbf;     Dbf3.Exclusive := True;     Dbf3.Open;     qtdbf:=Dbf3.recordcount; end; Procedure usedbf4(Var pathdbf: string; Var namedbf: string; Var qtdbf: integer; Var Dbf4: Tdbf); begin     Dbf4.FilePathFull := pathdbf;     Dbf4.TableLevel := 7;     Dbf4.Tablename := namedbf;     Dbf4.Exclusive := True;     Dbf4.Open;     qtdbf:=Dbf4.recordcount; end; ... ... ... Procedure closedbf2(Var styledbf: integer; Var Dbf2: Tdbf); begin    if styledbf=2 then     Dbf2.Post;    Dbf2.Close;    if styledbf=1 then     Dbf2.Free; end; Procedure closedbf3(Var styledbf: integer; Var Dbf3: Tdbf); begin    if styledbf=2 then     Dbf3.Post;    Dbf3.Close;    if styledbf=1 then     Dbf3.Free; end; Procedure closedbf4(Var styledbf: integer; Var Dbf4: Tdbf); begin    if styledbf=2 then     Dbf4.Post;    Dbf4.Close;    if styledbf=1 then     Dbf4.Free; end; ... ... Procedure skipdbf2(Var fichedbf: integer; Var Dbf2: Tdbf); begin  if fichedbf=1 then   Dbf2.First  else   Dbf2.Next; end; Procedure skipdbf3(Var fichedbf: integer; Var Dbf3: Tdbf); begin  if fichedbf=1 then   Dbf3.First  else   Dbf3.Next; end; Procedure skipdbf4(Var fichedbf: integer; Var Dbf4: Tdbf); begin  if fichedbf=1 then   Dbf4.First  else   Dbf4.Next; end; and now... after all procedure to access dbf tables are defined we can use all of them in our others procedure... an example Code: [Select]procedure TForm1.FormCreate(Sender: TObject); var style: string; repons: string; pathdbf: string; namedbf: string; qtdbf: integer; styledbf: integer; fichedbf: integer; nodbf: integer; ----comments pathdbf is the path of the table namedbf is the name of the table qtdbf is a variable to get the recordcount of the table ----- // Opening the Table   pathdbf:=PATHTABLE;   namedbf:=NAMETABLE;   usedbf4(pathdbf,namedbf,qtdbf,Dbf4); // Reading all records //   QTMES:=qtdbf;   SetLength(MYARRAY,QTMES);   i :=0;   for l1:=1 to QTMES do    begin     fichedbf:=l1;     skipdbf4(fichedbf,Dbf4);     MES[i] := Trim(dbf4.FieldByName('TEXTE').AsString);     i := i + 1;    end; // //close the Table   styledbf:=1;   closedbf4(styledbf,Dbf4); // styledbf is the way we want to close the table styledbf=0 is just to close styledbf=1 is for posting before to close styledbf=2 is for freeing memory after to close The way we close the table is important, especially if you want reuse many times the same procedure(as validate a name of employee in a table...) Have fun... from Santa Clauss Groenland And for anyone want to know more:  Documentation For official TDbf documentation PDF go to the SourceForge site. It may be useful to keep that pdf alongside this document while reading. http://sourceforge.net/projects/tdbf/files/TDbf documentation/TDbf documentation 1.1/ ---------------------------------------------------------------------- BigChimp · 2013-12-26 08:10 Thanks. Code: [Select]writeln('Did you know about the code button? That would make the spaghetti you posted above more readable.'); If there are things you miss on the tdbf tutorial at http://wiki.lazarus.freepascal.org/Lazarus_Tdbf_Tutorial please feel free to update it. Thanks a lot, BigChimp