help.. TBDF lazarus / 16-Databases ---------------------------------------------------------------------- suddendeath · 2011-04-18 08:55 Ok, so i'm a idiot! i downloaded the TBDF PDF and i don't get howto do search and retrieve information this is what i got so far can anyone help show me { notes :    Create( apath ) make sure that the path has delimiter \ } unit Unit2; {$mode objfpc}{$H+} interface uses   Classes, SysUtils,   Dbf, DB, Dbf_Common;  // fpc tbdf const   db_UserFile = 'USER.DBF'; type   TUserDatabase = class   private     FDBFile: TDbf;   public     constructor Create(aPath: string);     destructor Destroy; override;     function PackDataBase: boolean;     function NumUsers : LongInt;     function UserExist(aString : AnsiString) : LongInt;     function LoadUser(aString : AnsiString  Var aUser : TUserRec) : boolean;     function SaveUser(Var aUser : TUserRec) : boolean;     function UpdateUser(Var aUser : TUserRec) : boolean;   protected   end; implementation { lots of work here build the table bigger with entire user record } constructor TUserDataBase.Create(aPath: string); begin   FDBFile := TDbf.Create(nil);   FDBFile.FilePath := aPath;   FDBFile.TableLevel := 7;   FDBFile.TableName := db_UserFile;   if not (SysUtils.FileExists(aPath + db_UserFile)) then   begin     FDBFile.Exclusive := True;     with FDBFile.Fields do     begin       try         Add('User_ID', ftAutoInc, 0, True);         Add('Real_Name', ftString, 35, True);         Add('User_Name', ftString, 35, True);         Add('User_Password', ftString, 20, True);         Add('User_SL', ftInteger, 0, True);         Add('User_Flags', ftString, 52, True);         Add('User_Email', ftString, 80, True);         FDBFile.CreateTable;         FDBFile.Open;         FDBFile.AddIndex('idxUserID', 'User_ID', [ixPrimary, ixUnuque]);         FDBFile.AddIndex('idxUser_Name', 'User_Name', [ixCaseInsensitive]);         FDBFile.AddIndex('idxReal_Name', 'Real_Name', [ixCaseInsensitive]);         FDBFile.Exclusive := False;       finally       end;     end;   end   else     FDBFile.Open; end; destructor TUserDataBase.Destroy; begin  FDBFile.Exclusive:=True;  FDBFile.PackTable;  FDBFile.RegenerateIndexes;  FDBFile.Close;  FDBFile.Free; end; function TUserDataBase.PackDataBase: boolean; begin  FDBFile.Exclusive:=True;  FDBFile.PackTable;  FDBFile.RegenerateIndexes;  FDBFile.Close;  // not sure if i have to close - open but better safe  FDBFile.Open;  FDBFile.Exclusive:=False; end; Function TUserDataBase.NumUsers : LongInt; begin  FDBFile.RecordCount; end; Function TUserDataBase.UserExist(aString : ansiString) : longint; begin   FDBFile.Filter:='User_ID'[aString];   FDBFile.Filtered:=True;; end; end. ---------------------------------------------------------------------- javivf · 2011-04-27 08:23 Maybe with this... Quote from: suddendeath on April 18, 2011, 10:55:24 amFunction TUserDataBase.NumUsers : LongInt; begin   if not(FDBFile.Active) then     FDBFile.Open;   FDBFile.RecordCount; end; Function TUserDataBase.UserExist(aString : ansiString) : longint; begin   if not(FDBFile.Active) then     FDBFile.Open;   FDBFile.Filter:='User_ID'[aString];   FDBFile.Filtered:=True;; end; ---------------------------------------------------------------------- joseme · 2011-04-27 10:47 To be a function, your code must return something. My version of code: Code: [Select]Function TUserDataBase.NumUsers : LongInt; begin   if not(FDBFile.Active) then     FDBFile.Open;   result := FDBFile.RecordCount; end; Function TUserDataBase.UserExist(aString : ansiString) : boolean; begin   if not(FDBFile.Active) then     FDBFile.Open;   FDBFile.Filter:='User_ID'[aString];   FDBFile.Filtered:=True;   result := not FDBFile.Eof; end;            not sure if you  can filter  a DBF without closing, setting filter and condition and opening... ---------------------------------------------------------------------- garydale · 2011-07-25 18:45 The filter condition can be set and changed with an open database. It's applied dynamically so it can be slow - especially with complex filter conditions. Personally, I find the use of the Boolean "Filtered" condition to be annoying. If the filter is a null string, the table isn't filtered. If it isn't a null string then it should be applied. I don't see any advantage to making us turn a switch on and off when one can just as easily set and unset the filter string. Perhaps someone can explain why Filtered is used? ---------------------------------------------------------------------- garlar27 · 2011-07-25 19:08 QuoteI don't see any advantage to making us turn a switch on and off when one can just as easily set and unset the filter string. Perhaps someone can explain why Filtered is used?I think you should ask that to Delphi's developpers. Because that's the way they allways did it... But for me it has sense, spetially if you have a filter which is built progresively in your code. And if you want to disable that filter for a moment then you have to build it again