Zeos tutorial

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) português (pt) русский (ru) 中文(中国大陆)‎ (zh_CN)

Databases portal

References:

Tutorials/practical articles:

Databases

Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos

Overview

This tutorial is about getting, installing and using Zeoslib with Lazarus and FPC.

Getting Zeos

Zeos has recently been ported to Lazarus and there are no releases yet that officially support it but you can easily get it from SVN if you follow these steps:

SVN

Windows

Linux/BSD

ZIP

You can download the latest version as a ZIP file from sourceforge.net:

Installing the components

This is a tricky part so you should have a little patience and read this part carefully.

  • Make sure you have the latest Lazarus snapshot and the at least FPC 2.0.3 not older than 6th March 2006.
  • Start one instance of Lazarus.
  1. Use Components/Open Package File(.lpk) from the main menu.
  2. Go to zeosdbo_rework\packages\lazarus\ and open zcomponent.lpk. Note: Starting with Zeos 7.3 / 8.0 Zeos has a new zcomponentdesign package for Lazarus. Please use this package on these versions.
  3. Press [Compile] only if you don't want to install the components into the IDE
  4. Press [Install]
  5. You are asked if you want to recompile Lazarus.
  • Answer [Yes] this time.
  • Wait until compilation ends, Lazarus should restart itself after that.
  • If all is ok you should now be able to see the [Zeos Access] tab in the Component Palette.

Zeos Components.png

If you receive the error "Cannot find unit ZClasses" or something similar, then you need to carefully check the case of the filenames in your Zeos source distribution.

  • Even if the cases match exactly, the autogenerated package source file can generate the wrong case name in the uses clause (Lazarus 0.9.18), i.e.:
{ This file was automatically created by Lazarus. Do not edit!
  This source is only used to compile and install the package.
}
unit Zcore; 
interface
uses
  Zclasses, Zcollections, Zcompatibility, Zexprparser, Zexprtoken, Zexpression, 
  Zfunctions, Zmatchpattern, Zmessages, Zsysutils, Ztokenizer, Zvariables, 
  Zvariant; 
implementation
end.
  • Notice that Lazarus has named the unit ZClasses Zclasses, resulting in a naming conflict. Presumably this is a bug in Lazarus, not the Zeos packages. One way around this is to rename all the zeos source files to lowercase. Trawl through each subdirectory under src/ and execute this command in a bash window:
 rename -v 'y/A-Z/a-z/' *
  • Then, in Lazarus, reopen the package (.lpk) and fix the filename cases by clicking on "More..."/"Fix Files Case"
  • The package should compile now.

Installing Zeos components in MSEide

In order to install the Zeos components:

  • add the path to the Zeos source to 'Project'-'Options'-'Make'-'Directories'
  • and compile the IDE with -dmse_with_zeoslib -dMSEgui.
  • There is a predefined IDE project apps/ide/mseide_zeos.prj, update 'Project'- 'Options'-'Macros' according to your installation.
  • A simple demo is in mseuniverse.

Make your first Zeos application

  • Drop a ZConnection.
    • Set your User, Password, Host, Port and Protocol (and any other params if needed).
    • Set Connected to True.
  • Drop a ZQuery (do not mistake with ZReadOnlyQuery).
    • Set the Connection to your active ZConnection.
    • Set the Sql property to something like SELECT * FROM MyTable
    • Set Active to True.
  • Drop a DataSource from the [Data Access] tab.
    • Set the DataSet to your active ZQuery.
  • Drop a DBGrid from the [Data Controls] tab.
    • Set the Datasource to your DataSource.
    • If all is ok you should now be able to see the records from your table.

Possible Bugs and Issues

  • I have noticed that sometimes when building Lazarus it cannot find some Zeos files, as a quick workaround try this:
    • Use Components/Package Graph from the main menu.
    • Open the ZComponent package.
    • Right Click on the Files item in the list.
    • Choose [Recompile all required].
    • When asked "Re-Compile this and all required packages?" answer [Yes].
    • Recompile Lazarus normally (with packages).

See also