Zeos tutorial/zh CN

From Free Pascal wiki
Revision as of 09:56, 22 July 2012 by Swen (talk | contribs) (→‎下载 Zeos)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

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

概述

本教程讲述在Lazarus和Fpc上下载,安装并且使用Zeoslib 的方法。

最近Zeos 开发团队弄了一个新论坛. 无论是想了解关于Zeoslib 的其它信息,还是提问/回答有关使用Zeos 的问题, 或者是报告BUG , 请访问新论坛。ZeosLib新论坛地址.

下载 Zeos

Zeos网站最近搬迁到了Lazarus 网站, 而且还没有发布官方支持的新版本. 尽管如此, 遵从下列简单的几步就可以从SVN服务器获得源代码:

Windows 系统下

Linux/BSD 系统下

安装组件

安装比较棘手, 所以你应该有点耐心并仔细阅读本部分内容.(This is a tricky part so you should have a little patience and read this part carefully.)

  • 确认你使用的是最新版本的Lazarus 快照版本, 而且FPC版本至少是不早于2006.03.06日发布的2.0.3版.(Make sure you have the latest Lazarus snapshot and the at least FPC 2.0.3 not older than 6th March 2006.)
  • 启动一个Lazarus实例.(Start one instance of Lazarus.)
  1. 单击主菜单的Components/Open Package File(.lpk)命令. (Use Components/Open Package File(.lpk) from the main menu.)
  2. 打开zeosdbo_rework\packages\lazarus\目录下zcomponent.lpk文件.(Go to zeosdbo_rework\packages\lazarus\ and open zcomponent.lpk)
  3. 如果不想将组件安装到IDE中,则单击[Compile]按钮.(Press [Compile] only if you don't want to install the components into the IDE)
  4. 单击[Install]按钮(Press [Install])
  5. 提示"是否想重新编译Lazarus?"(You are asked if you want to recompile Lazarus. )
  • 这次,请选择[Yes]按钮.(Answer [Yes] this time.)
  • 耐心等待完成编译, 编译完成后Lazarus会自动重启.(Wait until compilation ends, Lazarus should restart itself after that.)
  • 如果一切正常, 你应该在组件面板中看到[Zeos Access]标签页.(If all is ok you should now be able to see the [Zeos Access] tab in the Component Palette.)

Zeos Components.png

如果编译过程中碰到诸如 "找不到ZClasses单元(Cannot find unit ZClasses)" 之类的错误提示, 请仔细检查 Zeos 源代码中的涉及到的相关文件名的大小写. (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.)

  • 注意, 在Lazarus 0.9.18中即使文件名大小写是完全一致的, 在自动生成的包(package)源文件的 "uses 单元"语句中, 仍然可能使用错误的大小写,如:(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.:)


 { 本文件系Lazarus自动生成.不要修改本文件内容!
   本源文件仅用于包的编译与安装. 
   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.           


  • 上例中, Lazarus 将ZClasses 单元写作Zclasses, 导致命名冲突. 估计这是Lazarus 而非Zeos 包的一个错误. 绕过这个错误的一个方法是将所有的Zeos 源文件名都改为小写. 方法是在命令窗口遍历src/ 目录下的每个子目录, 执行如下命令:(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/' *
  • 之后, 在Lazarus 中, 重新打开包文件(.lpk), 单击"更多.../修正文件名大小写"("More..."/"Fix Files Case")命令修正文件名的大小写.(Then, in Lazarus, reopen the package (.lpk) and fix the filename cases by clicking on "More..."/"Fix Files Case")
  • 现在,包文件应该能够正确编译了.(The package should compile now.)

备注

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)

制作你的第一个 Zeos 应用程序

  • 拖拉一个 ZConnection 控件.
    • 设置用户名, 密码, 主机, 端口和协议以及其它需要的参数.
    • 设置 Connected 属性为 True.
  • 拖拉一个 ZQuery 控件, 不要搞错拖拉了(ZReadOnlyQuery)控件.
    • 设置 Connection 属性指向上面的 ZConnection控件.
    • 设置 Sql 属性, 如 SELECT * FROM MyTable之类的SQL语句.
    • 设置 Active 属性为 True.
  • [Data Access] 标签页拖拉一个 DataSource控件.
    • 设置 DataSet 属性为上面的 ZQuery.
  • [Data Controls]标签页拖拉一个 DBGrid控件.
    • 设置 Datasource 属性指向上面的 DataSource控件.
    • 如果所有设置都正确的话, 你应该能看到表中的纪录内容.

关于 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 :)

可能的 Bug或问题(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.