* * *

Author Topic: How to open .dbf (Convert from Delphi) <SOLVED>  (Read 1742 times)

Jayndel

  • New member
  • *
  • Posts: 5
How to open .dbf (Convert from Delphi) <SOLVED>
« 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.
« Last Edit: July 22, 2018, 12:18:57 am by Jayndel »

Handoko

  • Hero Member
  • *****
  • Posts: 2611
  • My goal: build my own game engine using Lazarus
Re: How to open .dbf (Convert from Delphi)
« Reply #1 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

af0815

  • Full Member
  • ***
  • Posts: 171
Re: How to open .dbf (Convert from Delphi)
« Reply #2 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.
« Last Edit: July 20, 2018, 09:55:39 am by af0815 »
regards
Andreas

BrunoK

  • Jr. Member
  • **
  • Posts: 68
Re: How to open .dbf (Convert from Delphi)
« Reply #3 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.
Lazarus trunk 2018.10.01 (+/- patches regarding enabled). FPC 3.0.4 32 bits. Windows 10 Pro x64 (v. 1803)

af0815

  • Full Member
  • ***
  • Posts: 171
Re: How to open .dbf (Convert from Delphi)
« Reply #4 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
« Last Edit: July 20, 2018, 10:43:50 am by af0815 »
regards
Andreas

Jayndel

  • New member
  • *
  • Posts: 5
Re: How to open .dbf (Convert from Delphi)
« Reply #5 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.

Zath

  • Sr. Member
  • ****
  • Posts: 292
Re: How to open .dbf (Convert from Delphi)
« Reply #6 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.

Jayndel

  • New member
  • *
  • Posts: 5
Re: How to open .dbf (Convert from Delphi)
« Reply #7 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.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus