Difference between revisions of "Zeos tutorial/zh CN"

From Lazarus wiki
Jump to navigationJump to search
Line 15: Line 15:
 
Zeos has recently been ported to [[Glossary#Lazarus|Lazarus]] and there are no releases yet that officially support it but you can easily get it from SVN if you follow these steps:
 
Zeos has recently been ported to [[Glossary#Lazarus|Lazarus]] and there are no releases yet that officially support it but you can easily get it from SVN if you follow these steps:
  
Zeos最近迁移到了[[Glossary#Lazarus|Lazarus]] 站点, 而且还没有释出官方支持的新版本. 尽管如此, 遵从下列简单的几步就可以从SVN服务器获得最新开发版.
+
Zeos网站最近搬迁到了[[Glossary#Lazarus|Lazarus]] 网站, 而且还没有发布官方支持的新版本. 尽管如此, 遵从下列简单的几步就可以从SVN服务器获得源代码.
=== Windows版获取方式 ===
+
=== Windows系统获取方式 ===
  
 
* 下载小乌龟客户端([http://tortoisesvn.tigris.org TortoiseSVN]) 并且安装;
 
* 下载小乌龟客户端([http://tortoisesvn.tigris.org TortoiseSVN]) 并且安装;
Line 22: Line 22:
 
* 从Windows资源管理器检出源代码, 检出地址为 svn://firmos.at/zeos .
 
* 从Windows资源管理器检出源代码, 检出地址为 svn://firmos.at/zeos .
  
=== Linux/BSD获取ZEOS ===
+
=== Linux/BSD系统获取ZEOS ===
  
 
* 安装一个SVN客户端, 如esvn, kdesvn等等.
 
* 安装一个SVN客户端, 如esvn, kdesvn等等.

Revision as of 08:16, 29 September 2011

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

概览

This tutorial is about getting, installing and using Zeoslib with Lazarus and FPC.
本教程讲述在Lazarus和Fpc上获取,安装并且使用Zeoslib的方法。
The Zeos team has recently made a new forum. Please visit the new forum for more information about ZeosLib and to ask/answer questions about using Zeos and report bugs. The new forum can be found here Forum for ZeosLib.

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

获取 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:

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

Windows系统获取方式

Linux/BSD系统获取ZEOS

  • 安装一个SVN客户端, 如esvn, kdesvn等等.
  • 新建zeosdbo目录,然后在该目录执行:
  • "svn checkout"检出命令,检出地址为 svn://firmos.at/zeos .

安装组件

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

备注

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 应用程序

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

关于 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.