Lazarus

Installation => General => Topic started by: Jayndel on July 20, 2018, 07:49:45 am

Title: How to open .dbf (Convert from Delphi) <SOLVED>
Post by: Jayndel on July 20, 2018, 07:49:45 am
Hi all. Sorry if this isn't the correct way t ask, but after many years of db3+ -> Clipper > Delphi
I am completely stumped. For 5 days I have tried to find the code to simply open a dbf file as follows

PROCEDURE OpenPix ;   // <Delphi Code>
BEGIN
    Dir         := GetCurrentDir;
    dbPix      := TTable.Create(nil)   ;
    dbPix.TableType   := ttDBase   ;
    dbPix.DatabaseName   := Dir   ;
    dbPix.TableName   := 'Pix'   ;
    dbPix.Exclusive      := True   ;
    dbPix.Active   := True   ;
End;

I have looked everywhere, perhaps I'm too old to see the obvious, but I am really becoming desperate.
Any help would be REALLY appreciated.
Title: Re: How to open .dbf (Convert from Delphi)
Post by: Handoko on July 20, 2018, 07:58:50 am
Hello Jayndel,
Welcome to the forum.

Here has a demo showing how to open a dbf, display the data on a StringGrid and doing searhing in the grid:
https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361
Title: Re: How to open .dbf (Convert from Delphi)
Post by: af0815 on July 20, 2018, 09:50:19 am
The Code looks like using the Borland BDE. There is nothing equal in Lazarus. You can look in the Lazarus Wiki and search for dbf.
Edit: http://wiki.freepascal.org/Lazarus_Tdbf_Tutorial see Code example: creating a table/DBF file

The components in Lazarus works different if you use a desktop database like DBase.
Title: Re: How to open .dbf (Convert from Delphi)
Post by: BrunoK on July 20, 2018, 10:15:46 am
If you have Pix.DB and/or any Pix.MB, Pix.PX, Pix.XG0, Pix.YG0 etc... files then you probably have paradox table files.

In that case you need to install the $(LazarusDir)\components\paradox\lazparadox.lpk package and include paradox.pp in the unit clause off your program.

I think I remember having been able to read paradox tables this way but that's many years ago.
Title: Re: How to open .dbf (Convert from Delphi)
Post by: af0815 on July 20, 2018, 10:41:41 am
If you have Pix.DB and/or any Pix.MB, Pix.PX, Pix.XG0, Pix.YG0 etc... files then you probably have paradox table files
Quote from: Jayndel
wrote: dbPix.TableType   := ttDBase 
In BDE you must select the drivers and this says IMHO DBase (not ttParadox)

see: http://docwiki.embarcadero.com/RADStudio/Tokyo/de/Tabellentyp_f%C3%BCr_lokale_Tabellen_angeben
Title: Re: How to open .dbf (Convert from Delphi)
Post by: Jayndel on July 20, 2018, 09:41:34 pm
The database I am trying to access is actually a dBase3. dbf.

Unfortunately I have never previously used a visual database component, so I am rather lost.

Thank you all for your assistance. While learning a new system at 75 years of age is not so easy, it is reassuring to find there is such an active community willing to assist.

Again, many thanks.
Title: Re: How to open .dbf (Convert from Delphi)
Post by: Zath on July 20, 2018, 09:58:21 pm
Open the table with a spreadsheet such as excel by selecting Open and select .dbf dBase as the file type.
You can then save your data and use Lazarus to create a newer database program.
Title: Re: How to open .dbf (Convert from Delphi)
Post by: Jayndel on July 21, 2018, 01:47:51 am
Sorry about duplicate post, thought I had posted to incorrect section.
I now find I had mis-named the problem.
What I was trying to do was open a database in what was basically a console app. i.e. without using visual components

I finally sorted the problem..

var
  Form1: TForm1;
  Dbf1: TDbf;
  Dir   :    String;
  n     :    Integer;
                       

  Dbf1:=tDbf.Create(Self);
  Dir:=GetCurrentDir;
  Dbf1.FilePath := Dir;
  Dbf1.TableLevel := 7;
  Dbf1.Tablename := 'Games.dbf';
  Dbf1.Exclusive := True;
  Dbf1.Open;
  n:=Dbf1.recordcount; // Proof of Success  :D
  Dbf1.Close 

Many thanks for your help.
TinyPortal © 2005-2018