Install Packages/zh TW

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) magyar (hu) 日本語 (ja) português (pt) русский (ru) slovenčina (sk) 中文(中国大陆)‎ (zh_CN) 中文(台灣)‎ (zh_TW)

概述

基於大眾的需求,所以特此在此寫一篇簡短的 "安裝套件 HOW-TO"。


在安裝完 Lazarus 後很多新手常覺得奇怪找不到資料庫的元件使用。你可以參考一些[資料庫來源]的元件,但一般我們要用來連結資料庫的元件怎麼都不見了,何況是要從資料庫取出資料來?

好吧,讓我們來看看如何找到讓這可行的方法。

Lazarus 安裝的檔案

在 Linux 下你的 Lazarus 會安裝在 /usr/bin/lazarus 這個目錄,Mac OS X 下 Lazarus 是安裝在 /usr/local/share/lazarus,而 Windows 裡安裝程式會在安裝的時候給你自己挑,而且目錄裡不能有空白。在我的 Windows 下 Lazarus 安裝在 G:/Lazarus。然而這是 Lazarus 的根目錄,在底下你會找到一些子目錄,其中第一個 (依字母排序) 是 components

當你看到幾個子目錄後,就能讓我們聯想起幾個資料庫,像是Interbasemysqlsqlitesqldb的目錄。前三個包含了該資料庫連線的元件,而 TDataset 提供給各別系列的資料庫。最後一個 sqldb 比較廣泛,除了包含 TSQLQuery (TDataset) 與 TSQLTransaction 可以支援各類型的資料,T??Connection 則用於連線。


此文我們連同 Interbase 和 sqldb 套件一起安裝。

The real work

First: the why

Before we start installing a package I would like to discuss the why of Lazarus not installing database connection components. Database connection components need the client libraries to be available on the PC where the components are used. Because Lazarus does not currently support dynamic linking, all libraries have to be compiled into the IDE. As you cannot expect every developer to have all databases installed it is not possible to install the connection components by default.

Second: But Delphi ...?

Delphi also only installs the database components which are readily available on the computer (ADO components) and components which do not need any client libraries (BDE: Paradox, DBase) to be installed.

Third: Let's install some stuff

To install a package one goes to "Components -> Open Package File (.lpk)". In the following dialog you navigate to /usr/share/lazarus/components/sqldb or the corresponding directory under OS X or Windows and choose the sqldblaz.lpk file. If everything works out as planned you will see the Package Manager. The Package Manager is showing a treeview with the files in the package and the required packages. Now press Compile if you don't want to install the component into the IDE, otherwise you should press Install. Next we get a warning about Lazarus only supporting static linked libraries and the question if you want to rebuild Lazarus. Just press Yes and sit back. Lazarus will be rebuilt, and depending on your configuration restarted.

If everything went well you'll see a new tab called SQLdb. This tab will contain two components a TSQLConnection and a TSQLQuery. What we need next is a Connection component. Once again go to Components -> Open Package File and navigate to /usr/share/lazarus/components/sqldb/interbase. Open the ibconnectionlaz.lpk file and again press Compile and Install and Yes. :)

Next time Lazarus is started the SQLdb tab also contains a component TIBConnection.

in the meantime all supported components.

Anything else?

Well that is all there is to it. You're now set to make your first program connecting to an Interbase server. See this sources to download a small example. If you have any questions, go to the lazarus forum or post it to the lazarus mailing list.

Compile an IDE with packages at command line

There is no command line tool yet, to configure and setup the IDE config files to add/remove packages. You must setup this with an IDE, copy the configs and adapt the path. See here for details: Install IDE packages without the IDE. But the rest can be done on command line:

First build a normal IDE and LCL

 make clean all

Then compile the IDE with packages

This will build the packages to be installed, then the IDE and finally link all together:

lazbuild --build-ide=

The --build-ide parameter can take some options, for example -gh for heaptrc or '-gh -gt'.

See also