[newbie] Very simple example with DBGrid?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
littlebigman
Posts: 3
Joined: Mon 18 May 2009 15:13

[newbie] Very simple example with DBGrid?

Post by littlebigman » Mon 18 May 2009 15:18

Hello

Until now, SQLite was fine for my use, but I need to write a multi-user two-tier app and am giving Firebird a try.

I'm no Delphi expert, however, and would much appreciate a very simple example to using IBDAC with either DevExpress' or TMS' DBGrid object. Just a simple example showing how to connect, and perform basic commands like CREATE TABLE, SELECT, INSERT/UPDATE will do.

Thank you.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 19 May 2009 09:57

You can see IbDacDemo that is located in \Demos\[Win32]\IbDacDemo.

This demo uses standard TDBGrid but it shows how to connect and execute queries.

littlebigman
Posts: 3
Joined: Mon 18 May 2009 15:13

Post by littlebigman » Tue 19 May 2009 14:22

Thanks. I browsed through the demo but it's just too much to swallow for a Delphi newbie like me :-/

Here's a skeleton of what I'd like to do, ie. just connect to Firebird, create a database and a table, insert a couple of records, open a query to SELECT a dataset, fill this into a DBGrid, let the user edit data in the grid, and save the changes back to Firebird:

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBAccess, IBC, MemDS, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    IBCConnection1: TIBCConnection;
    IBCQuery1: TIBCQuery;
    IBCUpdateSQL1: TIBCUpdateSQL;
    IBCDataSource1: TIBCDataSource;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  With IBCConnection1 do begin
    //Define server + database
    Database := 'localhost:c:\test.firebird';
    //Project1.exe raised exception class EIBCError with message 'I/O error for file "c:\test.firebird"
    //Error while trying to open file The system cannot find the file specified. '.

    //Login + password
    Username := 'SYSDBA';
    Password := 'masterkey';
    //Connect and create database
    IBCConnection1.Connect;
    //INSERT a couple of records
  end;

  With IBCQuery1 do begin
    //Define SELECT to read all records
    //Open dataset
  end;

  {
  IBCDataSource1.DataSet := IBCQuery1;

  DBGrid1.DataSource := IBCDataSource1;
  //Configure DBGrid for in-place editing
  }

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  //Here, save changes done in DBGrid into Firebird server
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  IBCQuery1.Close;
  IBCConnection1.Disconnect;
end;

end.
Could a kind soul knowledgeable about Firebird/IBDAC fill me in on how to do this?

Thank you.

Post Reply