TDbf component lazarus / 16-Databases ---------------------------------------------------------------------- criki · 2017-01-18 17:01 Hello, I 'm trying to create a database throught the TDbf component BUT i got a 'Identifier not found' for the ftString that I use in a FieldDefs.Add( 'toto', ftString, 8, True) ??? Any idea ---------------------------------------------------------------------- Thaddy · 2017-01-18 17:13 I recall you have to add the db unit to the uses clause by hand for that to work, ftString is defined in the db unit. There is an old and unresolved bug report by me about that....( http://bugs.freepascal.org/view.php?id=29733 )  Fix that guys... So look at your code. If the db unit isn't in the uses, add it. Plz report back if it works. ---------------------------------------------------------------------- Handoko · 2017-01-18 18:00 I used TDbf. I've just checked my project files, not sure they are required or not but in my project I put these units in the uses clause: - dbf - dbf_fields - db ---------------------------------------------------------------------- Thaddy · 2017-01-18 18:58 Quote from: Handoko on January 18, 2017, 07:00:42 pmI used TDbf. I've just checked my project files, not sure they are required or not but in my project I put these units in the uses clause: - dbf - dbf_fields - db Yes, I did something like that. But it should be done automatically Delphi does that  Hence people are at a loss when they do not use the fields editor at design time and add fields in code. IMNSHO this is a BIG bug and an OLD bug. But once you add those by hand, it works. ---------------------------------------------------------------------- criki · 2017-01-18 20:12 Well thank's a lot guys .. in fact the db in uses seems mandatory ... but you are right it should be included automaticaly ... But until know the database create ends with a unable to open on the dfb1.createtable ... I need to check more .. Good night ---------------------------------------------------------------------- wp · 2017-01-18 21:01 You must be careful with the paths. If you enter a relative path in the property "Filepath" in the ObjectInspector then the IDE expands it to be relative the Lazarus binary folder. Enter the full path in the property FilePathFull. And after you completed all design works delete the filepath properties again and set the path at runtime. ---------------------------------------------------------------------- Handoko · 2017-01-19 02:32 @criki Can you show us your code? Below is part of mine which works correcly on both Win32 and Linux. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+} interface uses  Classes, SysUtils, dbf, dbf_fields, db, FileUtil  // add yours here  ; var  dbfMain: TDbf; const  DbfFileName = 'MyNote.dbf'; procedure OpenDatabase;begin   dbfMain := TDbf.Create(nil);  dbfMain.FilePathFull := ExtractFileDir(ParamStr(0));  dbfMain.TableName := DbfFileName;   with dbfMain do begin     // Create table and field if the table isn't existed    if (not(FileExists(FilePathFull+DirectorySeparator+TableName))) then begin      FieldDefs.Add('ID', ftInteger, 0, True);      CreateTable;    end;         Open;    // Do something here     Close;    Free;   end;end; ---------------------------------------------------------------------- Thaddy · 2017-01-19 12:41 @Handoko Excellent example. I have reduced it somewhat and can confirm your code works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program dbftest;{$ifdef fpc}{$mode delphi}{$H+}{$endif}uses  Classes, SysUtils, dbf, db;   var  dbfMain: TDbf; const  DbfFileName = 'MyNote.dbf'; procedure OpenDatabase;begin  dbfMain := TDbf.Create(nil);  with dbfMain do   try    FilePathFull := ExtractFileDir(ParamStr(0));    TableName := DbfFileName;    // Create table and field if the table isn't existed    if (not(FileExists(FilePathFull+DirectorySeparator+TableName))) then     begin      FieldDefs.Add('ID', ftInteger, 0, True);      CreateTable;    end;    Open;    // Do something here    Close;   finally    Free;    end;end;begin  OpenDataBase;end.Result is: Code: [Select]pi@raspberrypi:~ $ ls -l *.dbf -rw-r--r-- 1 pi pi 66 Jan 19 13:36 MyNote.dbf And that is a valid dbf. Anyway, somebody should finally fix that db omission from the uses clause (when using Lazarus and creating TDataset and fields in code). It is hard to know and find for average users. ---------------------------------------------------------------------- Michl · 2017-03-05 12:40 Quote from: Thaddy on January 19, 2017, 01:41:19 pmAnyway, somebody should finally fix that db omission from the uses clause (when using Lazarus and creating TDataset and fields in code). It is hard to know and find for average users.I read your bug report. Just as hint. It works semi automatic with package Cody (this is that one, I never miss to install on a new Lazarus installation). Try to compile your code without "db" in the uses clause: -> a error is shown in the message window "project1.lpr(21,27) Error: Identifier not found "ftInteger" " -> now right-click on it and click on "Show Cody Dictionary for "ftInteger" " -> select the first entry Thats it. Cody is learning identifiers by programming. For me, it saves a lot of time!