How to use Lazarus with Firebird?


Lazarus is a cross-platform clone of Delphi, so most of Delphi concepts and documentation should work. For example, you can use TIBConnection, TSQLQueery and TSQLTransaction components that are included with Lazarus for data connection and use TDBGrid, a TDBNavigator and TDBEdit as visual controls.

Some users reported success with recent versions of ZeosLib, so you might want to look into it:

http://wiki.freepascal.org/ZeosDBO

Some of the component libraries listed in FAQ #7 can also be used, so make sure you check them out. Getting some book on Delphi is also a good idea.

Detailed guide explaining how to use Lazarus with Firebird Embedded was available on the following page: voicixs.com/archives/198. Since the domain has expired, here's an archived copy with slight editing for grammar and language. You can use this guide to set up Lazarus for regular client/server applications as well:

1. Download Lazarus and install it:

http://www.lazarus-ide.org/

http://lazarus.freepascal.org/


2. Download and install Firebird

3. Create a database (hellodb.fdb) :

SET SQL DIALECT 3;

SET NAMES UTF8;
CREATE DATABASE 'PATH_TO_DB\HelloDB.fdb'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 16384
DEFAULT CHARACTER SET UTF8;

CREATE TABLE TBL_HELLO (TXT_FIELD CHAR(1000))

3. Download ZeosDBO:

http://wiki.freepascal.org/ZeosDBO

3.1 packages/lazarus/ZCore.lpk - Open/Compile
3.2 packages/lazarus/ZParseSql.lpk - Open/Compile
3.3 packages/lazarus/ZPlain.lpk - Open/Compile
3.4 packages/lazarus/ZDbc.lpk - Open/Compile
3.5 packages/lazarus/ZComponent.lpk - Open/Compile/Install

4. Open Lazarus and create new project HelloWorld and save it.

5. From Zeos Access tab, drag TZConnection and TZTable component to project

6. Configure TZConnection properties

// Database - PATH to HelloDB.fdb
// Hostname - localhost (blank for embedded)
// Protocol - database server/version (mine is firebirdd-2.1)
// User - SYSDBA (default Firebird username)
// Password - masterkey (default Firebird password)
// Connected - set to TRUE (now you are connected to your database)

If you're getting errors about missing DLL files, copy fbclient.dll from Firebird bin directory to Windows System32 and rename it to fbclientd.dll

7. Configure TZTable properties

// Connection - choose ZConnection1
// TableName - choose TBL_HELLO
// Active - set to True

8. From Data Access tab drag in TDatasource component

// Set DataSet property to ZTable1

9. From Data Controls tab drag in TDBnavogator

// Set Align property to alBottom
// Set DataSource property to Datasource1

10. From Data Controls tab drag in project TDBGrid

// Set Align property to alClient
// Set DataSource property to Datasource1
// Set AutoFillColumns to True

11. Build / Run project. Now you can insert Hello World text in database.

If you want to make client/server applications, then you're done at this point. If you want to use Firebird Embedded, read on:


12. Set TZConnection property Connected to False and then add the following code to OnCreate event for Form:

ZConnection1.HostName:='';
ZConnection1.Database:=ExtractFilePath(Application.EXEName)+'HELLODB.FDB';
ZConnection1.Connect;
ZTable1.Active:=true;

13. Build project.

14. Prepare a new empty directory. Let's call it EMB. Copy the following files from project directory into EMB:

HelloWorld.exe
HELLODB.FDB

15. Download Firebird embedded, separate download, zip kit.

16. Extract .zip and copy DLL files into EMB directory:

fbembed.dll
ib_util.dll
icudt30.dll
icuin30.dll
icuuc30.dll

17. Rename fbembed.dll to fbclientd.dll

18. Thats all, now you can stop/uninstall Firebird server. Just run HelloWorld.exe and you have application with fully functional embedded SQL server.


Do you find this FAQ incorrect or incomplete? Please e-mail us what needs to be changed. To ensure quality, each change is checked by our editors (and often tested on live Firebird databases), before it enters the main FAQ database. If you desire so, the changes will be credited to your name. To learn more, visit our add content page.



All contents are copyright © 2007-2024 FirebirdFAQ.org unless otherwise stated in the text.


Links   Firebird   News   FlameRobin   Powered by FB: Home Inventory   Euchre  
Add content   About  

Categories
 Newbies
 SQL
 Installation and setup
 Backup and restore
 Performance
 Security
 Connectivity and API
 HOWTOs
 Errors and error codes
 Miscellaneous