Add method parameters lazarus / 16-Databases ---------------------------------------------------------------------- johnmc · 2019-04-02 16:22 I asked in another topic about what the True parameter of the add method does lucamar kindly pointed me at the limited ducumentation but I need a fuller answer. Quote from: johnmc on April 02, 2019, 12:00:15 pmQuoteIt's in the documentation (and help files) for the FCL: Quote from: Reference for unit 'db' (#fcl)     TFieldDefs.Add : Add a new field definition to the collection.     Declaration     Source position: db.pas line 211     [...]     procedure TFieldDefs.Add(       const AName: string;       ADataType: TFieldType;       ASize: Word;       ARequired: Boolean     ); overload;     [...]     Arguments     AName       Value for the Name property of the new item.     ADataType       Value for the DataType property of the new item.     ASize       Value for the Size property of the new item.     ARequired       Value for the Required property of the new item.     [...] I interpreted that as meaning when True the field must be entered for the record to be written into the dataset, with an exception if not present. So the following should raise an exception but does not. 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 with WineDBf do    begin      TableLevel := 7;      Exclusive := True;    FieldDefs.Add('ID', ftAutoInc, 0, True);  // Field[0]      FieldDefs.Add('WineID', ftInteger, 0, True);      FieldDefs.Add('WineName', ftString, 60, True);      FieldDefs.Add('Vintage', ftString, 4, True);      FieldDefs.Add('Quantity', ftInteger, 0, True);      FieldDefs.Add('Size', ftString, 12, True);      FieldDefs.Add('Region', ftString, 25, True);      FieldDefs.Add('Country', ftString, 25, True);      FieldDefs.Add('Date', ftDateTime, 0, True);  // Field[8]      FieldDefs.Add('NoteID', ftInteger, 0, True);      CreateTable;      Open;       // Add data here      Append;      Fields[1].AsInteger := 1;      Fields[2].AsString := 'Ch. Smith Haut Lafitte';      Fields[3].AsString := '1988';      Fields[6].AsString := 'Bordeaux';    Fields[7].AsString := 'France';      Fields[4].AsInteger := 0;    Fields[5].AsString := 'Bottle';      //Fields[8].AsDateTime := StrToDateTime('10/2/1991');      Fields[9].AsInteger := 0;      Post;        AddIndex('idxByID', 'ID', [ixPrimary, ixUnique]);      AddIndex('idxByWineID', 'WineID', [ixUnique]);      AddIndex('idxByCountry', 'Country', [ixCaseInsensitive]);      AddIndex('idxByName', 'WineName', [ixCaseInsensitive]);      AddIndex('idxByNameRev', 'WineName', [ixDescending, ixCaseInsensitive]);    end; Does anyone know what this should do. ---------------------------------------------------------------------- howardpc · 2019-04-02 17:14 It would appear that although TDbf allows you to set the Required property for a field, its actual implementation does not enforce this. ---------------------------------------------------------------------- Zvoni · 2019-04-03 05:14 In layman‘s terms: you‘re not allowed to enter „nothing“ You must enter a valid (!) value ---------------------------------------------------------------------- Zvoni · 2019-04-03 05:16 Quote from: howardpc on April 02, 2019, 07:14:11 pmIt would appear that although TDbf allows you to set the Required property for a field, its actual implementation does not enforce this. Howard, of course it doen‘t enforce it, since the underlying real datatype of a date in a dbf is a String. It just fills it up with 8 zero-characters ---------------------------------------------------------------------- howardpc · 2019-04-03 06:05 To my mind there is no "of course" about such an approach to enforcing a requirement. You could equally say that if a required field has a blank/null value then "of course" an exception should be raised rather than a contrived value inserted. ---------------------------------------------------------------------- johnmc · 2019-04-03 09:34 As this is a datetime field I think it should be stored as a timestamp therefore as 2 long ints (2 x 4bytes). See https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm. For my example above I would expect an exception to be raised whatever the underlying data format being used to store it, otherwise why have it (required). So is this a bug? If so is it likely to be fixed? Where do I report it? ---------------------------------------------------------------------- Zvoni · 2019-04-03 10:02 Quote from: howardpc on April 03, 2019, 08:05:58 amTo my mind there is no "of course" about such an approach to enforcing a requirement. You could equally say that if a required field has a blank/null value then "of course" an exception should be raised rather than a contrived value inserted. Not if the Field has the Option "Default-Value" set to something, then NO, noone is going to enforce anything from you ---------------------------------------------------------------------- howardpc · 2019-04-03 10:15 Where in the code johnmc showed are any default values specified? ---------------------------------------------------------------------- Zvoni · 2019-04-03 10:21 True, but i found something else going through dbf_fields.pas What Version of dbase is he using? 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 procedure TDbfFieldDef.VCLToNative;begin  FNativeFieldType := #0;  // to do: look into ftBytes support; e.g. Visual FoxPro varbytes?  case FFieldType of    {ftAutoInc  :      if DbfVersion=xVisualFoxPro then      FNativeFieldType  := 'I'      else        FNativeFieldType  := '+'; //Apparently xbaseV/7+ only; not (Visual) Foxpro}    ftDateTime :      if DbfVersion = xBaseVII then        FNativeFieldType := '@'    else      if (DbfVersion = xFoxPro) or (DbfVersion = xVisualFoxPro) then        FNativeFieldType := 'T'      else        FNativeFieldType := 'D'; There. If it's dBaseVII then ftDateTime tranlates to "@", if it's FoxPro it translates to "T", everyting else to "D", WHICH IS A STRING IN FORMAT "YYYYMMDD" Next: 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 {$ifdef SUPPORT_DEFAULT_PARAMS}    procedure Add(const Name: string; DataType: TFieldType; Size: Integer = 0; Required: Boolean = False);{$else}    procedure Add(const Name: string; DataType: TFieldType; Size: Integer; Required: Boolean);{$endif}There! Do we know what switches are turned on in his program? ---------------------------------------------------------------------- howardpc · 2019-04-03 11:07 I find that  dbf_common.inc has this at line 214: 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   {$define SUPPORT_DEFAULT_PARAMS} ---------------------------------------------------------------------- johnmc · 2019-04-03 13:59 From what you have howardpc and zvoni are saying is that it won't work because theres is some setting buried in the TDbf source code that disables it. That does seem to make things difficult. I did find a reponse to a query on the Sourceforge TDbf forum that says it is not implemented, although that dates from 2003, the author of the comment was Micha Nelissen. https://sourceforge.net/p/tdbf/discussion/107245/thread/b440c61a/ ---------------------------------------------------------------------- Zvoni · 2019-04-03 20:22 John, i repeat, what i said in your other thread: create yor dbf, fill it with sample data, and then try to open it in Excel, Access, whatever. The only thing you need is the ISAM-Driver (AFAIK. It's been 20 years for me working with such stuff) https://smallbusiness.chron.com/convert-dbf-xls-55554.html EDIT: What i'd like to know: Why in blazes are you using such an archaic format? If you need filebased, i'd say SQLite! ---------------------------------------------------------------------- johnmc · 2019-04-04 08:14 It seemed like a good idea when I started out. A database without having to install anything else. And to be fair it has allowed me to build a simple app that works. It may not be the most robust app. I can read, write sort and filter records. I am now begining to understand some of the limitations of my choices but it has given me some insight into how to find solutions to my problems. I will probably continue with this for a little longer while I make a choice as to which route to take from here. Thanks for all your help so far. John ---------------------------------------------------------------------- Zvoni · 2019-04-04 08:38 Well, SQLite has been around now for over 18 years, and is one (if not THE) most popular filebased database. FPC/Laz supports it natively. For Design i'd recommend DB Browser for SQLite and/or SQLiteStudio. You'll notice that finding information on SQLite is much easier than on dBase, especially if you're struggling with an issue, you'll probably get it solved much quicker, since most of us are familiar with it. The only thing to remember is, when shipping your program under Windows, to ship the sqlite3.dll with it (if it's not already installed on the target). As a last advice to you (and unfortunately this applies to SQLite too!): If you're using a Database, which doesn't have a "native"-DateTime-DataType (like dBase and SQLite --> SQLite stores it as some weird String IIRC), i'd rather choose Double (If you want to store Date and Time) or Integer (if only Date), because, internally, that's what a Date/Time actually is! DateTime --> Double --> The integer-part being the Day since BaseDay, the Fraction the Time of that day I just did a "Debug.Print CLng(Now)" in VBA/Excel, and it returned 43559, meaning: 43559 days have passed since your BaseDay (Whatever that is) As Double "Apr 4th 2019 - 6PM" would equal 43559.75 (The fraction being the Time-part --> at 6PM 3/4 of a day have passed) ---------------------------------------------------------------------- dsiders · 2019-04-04 09:30 Quote from: johnmc on April 04, 2019, 10:14:50 amIt seemed like a good idea when I started out. A database without having to install anything else. And to be fair it has allowed me to build a simple app that works. It may not be the most robust app. I can read, write sort and filter records. I am now begining to understand some of the limitations of my choices but it has given me some insight into how to find solutions to my problems. I will probably continue with this for a little longer while I make a choice as to which route to take from here. Thanks for all your help so far. John I'm partial to Firebird 3 Embedded. It's a solid SQL database with a light footprint, and the added benefit of talking to its full-fledged remote server if needed. Check out: http://www.ibphoenix.com/files/Embedded_fb3.pdf But I do have fond nostalgic memories of Clipper and DBFs from the 1980's and 1990's. ---------------------------------------------------------------------- Zvoni · 2019-04-04 09:33 Quote from: dsiders on April 04, 2019, 11:30:39 amBut I do have fond nostalgic memories of Clipper and DBFs from the 1980's and 1990's. I don't........  Especially during economy-school in 1996-1997 doing the queries with that dBase-Syntax from the commandline. What was it? List something blahh i think We were the last class to learn dBase, the following class already switching to Access (Hell, yeah!). The end result in my final exam was, that i had a choice of DB-System to answer my questionaire. I choose Access, which everybody proclaimed me insane, since we didn't learn it in class. The funny thing: The examiners had prepared some fancy sheets, with screenshots from this Access-Query-Builder-Window (no idea what's its name) for the students just to fill out the fields. I just drew a diagonal line through that sheet, and wrote below: "See solution on my extra sheet", where i wrote down the SQL-command....... Got a straight "A" for my final exam, which was scheduled for 60 minutes, and i was done after 15. Examiner (seeing me come to the frontdesk after 15 minutes into the exam): "Yes? Something unclear?" Me: "No. I'm done" *dead silence in the classrom* Examiner: "Err? You sure? Don't you want to look..*interrupt*" Me: "No! I'm done. (turning around to my classmates) See you in the pub next street in an hour!"