Recent

Author Topic: How to use database  (Read 4219 times)

Lohot

  • Newbie
  • Posts: 1
How to use database
« on: January 16, 2007, 12:36:07 pm »
Hi,

I used Delphi and I try Lazarus to create a program with database.

I create DBASE VII with this code :

Code: [Select]
begin
  Source := ExtractFilePath(Application.Name);
  MyDbf := TDbf.Create(nil);
  if not DirectoryExists(Source + 'data') then
     if not CreateDir(Source + 'data') then
        raise Exception.Create('Impossible de créer le répertoire');
  try
    { use relative path to "data" directory }
    MyDbf.FilePath := 'data';
    { we want to use Visual dBase VII compatible tables }
    MyDbf.TableLevel := 7;
    MyDbf.Exclusive := True;
    MyDbf.TableName := 'customers.dbf';
    With MyDbf.FieldDefs do begin
      Add('Id', ftAutoInc, 0, True);
      Add('Name', ftString, 80, True);
    End;
    MyDbf.CreateTable;
    MyDbf.Open;
    MyDbf.AddIndex('custid', 'Id', [ixPrimary, ixUnique]);
    { add a secondary index }
    MyDbf.AddIndex('custname','Name', [ixCaseInsensitive]);
finally
    MyDbf.Free;
  end;


With Delphi, To add something in the database, I used TTable but there's not TTable in Lazarus.

Can you give me a link to an exmaple of code with a database management.

Thanks

Lohot

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: How to use database
« Reply #1 on: January 16, 2007, 01:11:22 pm »
Did you look at the Lazarus TDbf tutorial?

 

TinyPortal © 2005-2018