Recent

Author Topic: [SOLVED] TDbf  (Read 1945 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] TDbf
« on: September 24, 2023, 05:29:54 pm »
Hi All,
   I'm new to Lazarus coming from Delphi 7 long time ago. I have designed a pascal system since the early nineties, most of the development I did was when I own my own company designing software for the personel placement industry, i.e. head-hunters & temporary/contractor placement firms.
   In retirement I started a hobby in photography.  A friend of mine was talking about he wished he had a small software system to manage his photography business.  So, here I am having fun designing a small system with Lazarus/FP.
   The system is similar to Delphi so easy to get going.  My problem is that I thought I'd use the TDbf component for the data. I found a neat little app called My DBF Studio and designed a Database/Table with 3 indexes defined.
   Anyway, making a long story short. Placed the TDbf component on my form. Then made it active so I could assign the Database Table defs. Defined the FilePath, Table Name, easy enough. But, Lazarus doesn't recognize the table or anything. I can't an IndexFieldName, MasterSource, MasterFields, FieldDefs, IndexName. Version is 7.0, TableLevel 4. I think it defaulted to these values for TableLevel and Version.
   Anyone have experience with any of this and could advise what I'm doing wrong or left out?
Tks & advise, Donald aka 1HuntnMan
« Last Edit: February 10, 2024, 08:39:21 pm by 1HuntnMan »

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: TDbf
« Reply #1 on: September 24, 2023, 05:55:57 pm »
At least the version of MyDBFStudio which I maintain comes with two sample dbf files. Can you open these in your application?

You can find a tutorial how to use the TDbf component at https://wiki.freepascal.org/Lazarus_Tdbf_Tutorial. It also contains a section how to create a dbf database by code, independent of MyDBFStudio.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDbf
« Reply #2 on: September 24, 2023, 08:39:14 pm »
I'll try opening your samples. If that works, then I'll get back to you and will be more confused because I created my table with MyDBFStudio. I have the Lazaraus_Tdbf_Tutorial link saved at the top of my browser and could create the database via code but thought it would be easier to use a tool such as your MyDBFStudio. I had also downloaded another app called DBF Manager which isn't as intuitive as your app.  I can open the .DBF I created with MyDBFStudio. and DBF Manager also sees the indexes also created with your app.
If I can't figure this out then I'm going to either create the table via code in my app or move to SQLite.
Tks for your reply/advice,
Donald

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: TDbf
« Reply #3 on: September 24, 2023, 10:10:02 pm »
You were saying that you created indexes for the dbf file. I am aware that the TDbf which comes with FPC has issues with indexes, and this is the reason why I used in MyDBFStudio the original TDbf from which the FPC version was forked. If I can confirm your issues I could try to figure out a way how to load the dbf in Lazarus.

Could you send me the table that you created with MyDBFStudio? If you don't want to publish it put it on some cloud server and send me the link via PM.


eldonfsr

  • Hero Member
  • *****
  • Posts: 524
Re: TDbf
« Reply #4 on: September 24, 2023, 10:36:12 pm »
why TDBF could be better to use sqlite....think is local database

iret

  • New Member
  • *
  • Posts: 15
Re: TDbf
« Reply #5 on: September 24, 2023, 11:36:29 pm »
Having used TDbf and sqlite in my Delphi and lazarus apps I strongly recommend to use sqlite.

DBase is really outdated and the TDbf FPC components have major bugs concerning index files. If you really want to use dbase files you should use the original TDbf from sourceforge (Note: The licence  does not allow commercial use without giving the source code to your customers)

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: TDbf
« Reply #6 on: September 25, 2023, 12:34:52 am »
The advantage of TDbf is that is self-contained and does not depend on external libraries. And for a user coming from Delphi 7 it is probably easier to enter the database world than using the more complicated sqlite3. I do agree, however, that in the long term the application should switch to sqlite3, in particular for a business.

eldonfsr

  • Hero Member
  • *****
  • Posts: 524
Re: TDbf
« Reply #7 on: September 25, 2023, 01:22:13 am »
Did you tried Zmqsl  if not want to use external lib is other option ....

MDataset just save to file of  table information.... and to load assign file to mdataset loadfrom

but all depend how much information you wanna handle from table or database

 

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDbf
« Reply #8 on: September 27, 2023, 09:45:44 pm »
Thanks for the great info.  I created the main form with menu and speed-buttons similar to the way I used to design Delphi apps.  The first form was a contact mgt. form. Just a form to add a new contact and the basic info., address, etc.  I added a TDbf component on this contacts form. I created a Table with My DBF Studio that I found via the web and used that to create the table and added one record. I added components db, dbf, etc. to the unit. Everything seemed hunky-dory but in the properties for the table I told Lazarus via the path where the table was located (folder just below where the app was located). The problem was the properties wanted to know the datasource, database, etc.  None of these properties were active. Clicking on them, blank!  But the fields loaded into the component area so I could add dbedits, etc. But, Lazarus wasn't happy. I would crash now and again.  I gave up and uninstalled Lazarus and reinstalled.  I'm going to start all over with SQLite.  I created the Database and a table with DB Browser (SQLite).  Hopefully and can get to programming without all the headache of just getting a database connected and move on the life!  My first experience with Lazarus wasn't easy like when I first started programming w/Delphi 5 then 7. For designing database software with Delphi for a small business I just used a Database that came with Delphi that the tables were just *.DB, indexes: *.IDX & blob *.BLB. 
Getting started has been a pain, hopefully SQLite won't be such an issue.  I've seen some info of importing a Delphi app into Lazarus, so far I can't see how you could do that with the issues Lazarus has with the database conversion. Oh well, I'll see here in an hour or so! LoL

wp

  • Hero Member
  • *****
  • Posts: 12457
Re: TDbf
« Reply #9 on: September 27, 2023, 11:15:28 pm »
but in the properties for the table I told Lazarus via the path where the table was located (folder just below where the app was located).
In general, this is not a good idea because it hard-codes the location of the dbf file into the lfm which makes your app fail when the directory structure changes. And when you type in a relative path (e.g. "data") this refers to the location of the app only at runtime; at designtime it refers to the location of the lazarus.exe! Also, do not save the form with the dbf.Active property set to true, because this will prevent your application form starting when one of these issues occurs.

Better to write code in the OnCreate event of the form to open the database:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Dbf1.TableName := 'name_of_the_dbf_file.dbf';
  4.   Dbf1.FilePathFull := 'data';   // this is the RELATIVE path to the dbf file as seen from the exe at runtime
  5.   Dbf1.Active := true;
  6. end;

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 276
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDbf
« Reply #10 on: September 28, 2023, 07:37:26 pm »
I'll let you know, will try using a dbase file again.

 

TinyPortal © 2005-2018