Zeos tutorial/fr

From Free Pascal wiki
Revision as of 15:54, 18 April 2012 by Milarepa (talk | contribs)
Jump to navigationJump to search

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

Avant-propos

Ce tutoriel concerne le téléchargement, l'installation et l'utilisation de Zeoslib avec Lazarus et FPC.

Les développeurs de Zeos mettent à disposition un forum. Pour plus d'informations sur ZeosLib, pour poser (ou répondre à) des questions sur l'utilisation de Zeos et pour des rapports de bugs, veuillez vous rendre sur le forum ZeosLib.

Téléchargement de Zeos

Zeos a été porté sur Lazarus. Il n'y a pas de distribution officielle mais vous pouvez aisément le télécharger via SVN en suivant les étapes suivantes :

Windows

(je n'ai aucune expérience sous Windows. Si quelqu'un peut taduire et mettre à jour son expérience ici...)

Linux/BSD

Installation des composants

C'est une partie délicate de l'opération. Il vous faudra un peu de patience et lire attentivement ces instructions.

  • Assurez-vous que vous avez une version récente de Lazarus ainsi qu'un FPC plus récent que celui de mars 2006 (ces instructions sont relativement vieilles. Au moment de cette traduction FPC 2.6.0 et Lazarus 0.9.30 sont disponibles).

Pour les versions Lazarus et FPC mentionnées ci-dessus, il faut faire un changement dans le fichier <votre répertoire zeosdbo>/trunk/src/core/ZCompatibility.pas : Remplacer

 {$IFDEF FPC}
   dynlibs,
 {$endif}

par

 {$IFDEF FPC}
   dl,
 {$endif}.

(merci à ludob qui a donné cette solution dans http://www.lazarus.freepascal.org/index.php/topic,16615.msg90797.html#msg90797)

  • Démarrez Lazarus.
  1. Allez dans Paquet/Ouvrir un fichier paquet(.lpk) dans le menu principal.
  2. Allez dans <votre répertoire zeosdbo>/trunk/packages/lazarus/ et ouvrez zcomponent.lpk
  3. Cliquez sur [Compiler] si vous ne voulez pas installer les composants dans l'IDE
  4. Cliquez sur [Installer]
  5. On va vous demander si vous voulez reconstruire Lazarus.
  • Répondez [Oui].
  • Attendez un moment. Si tout va bien, Lazarus devrait redémarrer.
  • Maintenant, vous devriez voir l'onglet [Zeos Access] dans la palette de composants.

Si vous avez une erreur du type "Cannot find unit ZClasses" ou quelque chose d'approchant, recherchez dans les noms de fichiers des sources de Zeos.

  • Parfois, les fichiers source auto-générés peuvent avoir une casse incorrecte ce qui bloque sous Unux/Linux :


 { 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.

Comments

Currently Zeos CVS for Lazarus has broken packages. Some comments from IgD:

Using a fresh install of Laz 0.9.12 (latest stable version) I was able to install ZeosLib dated 13 Oct 05. First fix the following bugs in ZeosLib:

  • 1. Change ZplainPostgreSql81.pas to ZPlainPostgresSql8x.pas in zplain.lpk
<Item22>
  <Filename Value="../../src/plain/ZPlainPostgreSql81.pas"/>
  <UnitName Value="ZPlainPostgreSql8x"/>
</Item22>

  • 2. Fix the following typos in zdbc.lpk:

a. Remove extra "/" from "build/" (remove the one that is inside the quotes)

<SearchPaths>
  <OtherUnitFiles Value="../../src/dbc/"/>
  <UnitOutputDirectory Value="build/"/>
</SearchPaths>

b. Add missing quote to unitname value

<Item43>
  <Filename Value="../../src/dbc/ZDbcASA.pas"/>
  <UnitName Value="ZDbcASA/>
</Item43>

Now, here are the installation instructions:

Before Lazarus 0.9.13 you must open each of the zeos packages via Components/Open Package File in the following order:

  1. zcore.lpk
  2. zparsesql.lpk
  3. zplain.lpk
  4. zdbc.lpk

Then finally open zcomponent.lpk and compile and install this package. 0.9.13 can simply open zcomponent.lpk. The IDE will open the rest automatically.

Note: The first four packages only need to be compiled and cannot be installed.

--Forest 17:41, 2 Nov 2005 (CET)

  • 3. If you compile and install with sucessfull Zeos, but Lazarus, after rebuilded, start with:

Zeoserror.gif

Then you can do:

In Zeos.Inc file replace, in section "// Settings for Debug mode": {$R-} to {$R+}

--Junior 19:48, 15 Apr 2006 (GMT)

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.

More information about working with Zeos

Here you can find some really useful articles explaining Zeos usage and it's internals, some of them also talk about Delphi specific stuff but mostly the same techniques can be used in Lazarus too.


Please complete me :)

Possible Bugs and Issues

  1. I have noticed that somethimes 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).

  2. There is a bug in FPC's AnsiStrComp wich causes unreliable PChar comparison, this is obvious when using a DBGrid to edit data, AnsiStrComp('abc', 'abcd') can't detect them as being different but it detects AnsiStrComp('abd', 'abcd') ignoring multiple chars from the second string. This bug was found by Jesusrmx. It will probably be fixed soon, see Bug Report.