Difference between revisions of "Lazarus Tutorial/zh TW"

From Free Pascal wiki
Jump to navigationJump to search
Line 167: Line 167:
 
* '''程序清單''':建立一份目前檔案裡所有程式與函式的清單,並加註他們宣告處所在的行號。
 
* '''程序清單''':建立一份目前檔案裡所有程式與函式的清單,並加註他們宣告處所在的行號。
  
==== The View sub-menu ====
+
==== 檢視子選單 ====
 
<div class="floatright"> [[Image:ViewMenu.png]] </div>
 
<div class="floatright"> [[Image:ViewMenu.png]] </div>
Controls the display of various windows and panels on the screen.
+
控制螢幕裡各個視窗與面版的一些顯示。
* '''物件檢視器''': The window that usually occupies the left side of the Desktop, and displays the features of the Form which is on the desktop.  Clicking with the mouse on any component of the form will cause the details of that component to be displayed in the 物件檢視器.  There is a panel at the top which shows the tree-structure of the current project, and the components of the form may optionally be selected in this panel:  this will also cause the corresponding details to be displayed in the 物件檢視器.  The main lower panel has two tabs which allow selection of either '''Properties''' or '''Events''' to be displayed.  Selection of '''Properties''' causes features such as name, color, caption, font, size etc to be displayed:  there are two columns, the left showing the property, and the right showing the value associated with that property. Selection of '''Events''' displays two columns:  the left lists the possible events such as MouseClick or KeyDown associated with that component, and the right shows the action that results from that event.  If there is no action defined, then clicking in the appropriate box or on the <div class="box">...</div> button causes the 原始碼編輯器 to be displayed, with the cursor already positioned in a dummy Procedure declaration, waiting for event-defining code to be typed in.
+
* '''物件檢視器''':這個視窗通常都一直佔據在你桌面的左方,顯示您表單的特徵。滑鼠選的所有表單裡的物件,詳細內容都會在物件檢視器裡顯示。上半的面版有一個專案的樹狀圖,分列出表單裡的元件供選取。這和物件檢視器所提供的是一致的。主要的下半面版顯示有兩個籤頁,'''內容''''''事件'''。選擇'''內容'''會顯示的特徵有如命名,顏色,字型,尺寸等:這部份分成兩欄,左半是寫內容名稱,右半則是與內容關聯的值。選擇'''事件'''會顯示兩欄:左半一樣是事件名稱,如關聯到元件的 MouseClick 或 KeyDown,而右邊就是事件發生後要進行的動作。如果沒有定義任何動作,按一下刪節號 <div class="box">...</div> 會跳回原始碼編輯器,游標會停在一個空的程序裡,等待你把程式內容寫進去。
 
* '''原始碼編輯器''': The main window in which source code is edited.  Its behaviour is very like that of most other graphical text editors, so that the mouse can move the cursor over the displayed text, and clicking with the left mouse button while dragging the mouse will select and highlight text.  Right clicking with the mouse displays a pop-up menu, it includes the usual Edit Cut, Copy or Paste functions, ''Find Declaration'' and ''Open File at Cursor''.  The top of the 原始碼編輯器 window has a number of tabs, corresponding to the files that are open for the current project;  clicking on any tab makes that file visible, and you can move easily from file to file, copying and pasting between files and performing most of the normal editing functions.  The 原始碼編輯器 performs color syntax highlighting on the code, with different colors for punctuation marks, comments, string constants etc.  It will also maintain the level of indentation from line to line as you type in code, until you change the indentation.  The function and appearance of the 原始碼編輯器 are very configurable from the Main Menu by selecting Environment -> Editor options and then selecting one of several tabs in the pop-up dialog box.
 
* '''原始碼編輯器''': The main window in which source code is edited.  Its behaviour is very like that of most other graphical text editors, so that the mouse can move the cursor over the displayed text, and clicking with the left mouse button while dragging the mouse will select and highlight text.  Right clicking with the mouse displays a pop-up menu, it includes the usual Edit Cut, Copy or Paste functions, ''Find Declaration'' and ''Open File at Cursor''.  The top of the 原始碼編輯器 window has a number of tabs, corresponding to the files that are open for the current project;  clicking on any tab makes that file visible, and you can move easily from file to file, copying and pasting between files and performing most of the normal editing functions.  The 原始碼編輯器 performs color syntax highlighting on the code, with different colors for punctuation marks, comments, string constants etc.  It will also maintain the level of indentation from line to line as you type in code, until you change the indentation.  The function and appearance of the 原始碼編輯器 are very configurable from the Main Menu by selecting Environment -> Editor options and then selecting one of several tabs in the pop-up dialog box.
 
* '''Code Explorer''': A window usually placed on the right of the Desktop which displays, in tree form, the structure of the code in the current unit or program.  It usually opens with just the Unit name and branches for Interface and Implementation sections, but clicking on the <div class="box">+</div> box to the left of any branch will open up its sub-branches or twigs, in more and more detail until individual constants, types and variables are displayed as well as procedure and function declarations.  If you change the file displayed in the main 原始碼編輯器 window, you need to click on the Refresh button of the Code Explorer to display the structure of the new file.
 
* '''Code Explorer''': A window usually placed on the right of the Desktop which displays, in tree form, the structure of the code in the current unit or program.  It usually opens with just the Unit name and branches for Interface and Implementation sections, but clicking on the <div class="box">+</div> box to the left of any branch will open up its sub-branches or twigs, in more and more detail until individual constants, types and variables are displayed as well as procedure and function declarations.  If you change the file displayed in the main 原始碼編輯器 window, you need to click on the Refresh button of the Code Explorer to display the structure of the new file.

Revision as of 10:39, 6 December 2010

Deutsch (de) English (en) español (es) suomi (fi) français (fr) magyar (hu) italiano (it) 日本語 (ja) македонски (mk) Nederlands (nl) português (pt) русский (ru) slovenčina (sk) shqip (sq) 中文(中国大陆)‎ (zh_CN) 中文(台灣)‎ (zh_TW)

這是篇 Lazarus 教學的起頭,各位可自由地改進他。

概述

Lazarus 是一個使用 Pascal 編譯器的自由開放原始碼開發工具。Free Pascal 本身也是自由開放軟體。Lazarus IDE (擷圖) 提供一穩定,且專注於強調豐富的程式寫作環境,並用來開發單機的圖形與主控台應用程式。Lazarus 目前可以在 Linux,Mac OS X 與 Win32 下執行。且提供可自訂的原始碼編輯器,並透過套件管理,除錯器與完整的圖形使用介面整合的編譯器做成視覺化的表格創建環境。

我們開始吧

(感謝 User:Kirkpatc)

取得並安裝 (Installing Lazarus) Lazarus,同時安裝所有所需的 Free Pascal 編譯器後執行 Lazarus。

註:在 Linux Ubuntu 下,在主控台啟動 Lazarus 的指令是 "startlazarus"。如果你是從 Debian 的套件來安裝,你應該會在開始選單裡的應用程式/程式寫作 (Application/Programming) 下找到程式捷徑來啟動。 (己知問題: 在 Debian 或 Ubuntu 裡的主要執行檔與套件已經改名成 "lazarus-ide",因為已經有個 "tct" 的工具套件被取名叫 "lazarus"。)


你的第一個 Lazarus 程式!

從主選單裡,選擇〔專案〕 - 〔新增專案-應用程式〕 (Project - New Project-Application)。 幾個視窗會出現在你的桌面上:上方的主選單,左方的物件檢視器,Lazarus 原始碼編輯器佔桌面的一大半部份,並有一個已經備妥的 Form1 視窗於原始碼編輯器重疊著出現。 在上方的選單視窗,選單列的下方,有一排標籤頁。如果 '標準 (Standard)' 籤頁沒有被選取,請用滑鼠點選他。然後找到〔按鈕〕 (Button) 的圖示 (一個裡面寫著 'OK' 的四方形) 後用滑鼠按一下,游標再移到 Form1 的視窗,大概移到中間偏左的地點再按一下滑鼠鍵。一個立體的四方形,標著 'Button1' 的按鈕物件就會出現。再按一次標準籤頁裡的鈕按圖示,然後移到 Form1 中間偏右的地方再按一次,就會出現一個標著 'Button2' 的按鈕出現。

現在點一下 Button1 來選取它。物件檢視器會顯示出該 Button1 物件的所有內容,靠上的有一項名為 '標題 (Caption)' 的內容,裡面顯示的值是 'Button1'。點一下那個方格,將 'Button1' 改成 '按我'。如果你再按一下 ENTER 或點一下其它的方格,你就會見到原來第一個按鈕裡面標的字就會變成 '按我'。現在點選物作視察器裡的〔事件〕 (Events) 籤頁,裡面會列出所有與這個按鈕有關的事件項目。像是 OnClick,OnEnter,OnExit 等等。再選取 OnClick 右邊的方格,方格會出現三個小點的省略符號。當你再按取該省略符號,會你自動被帶進入原始碼編輯裡,且游標被定在你該撰寫讓事件原始碼的開始處:

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   {現在輸入:}    Button1.caption := '再按一次';
   {程序於此完結}
 end;

按一下 F12 從原始碼編輯器回到 Form1 的視窗。

現在接著編輯 Button2 的〔內容〕:按一下 Button2 使物件檢視器裡顯示出它的內容,變更他的〔標題〕成 '離開'。然後接著再選 OnClick 事件,再點省略符號,這時你又回到原始碼編輯器,從另一段程序開始寫作:

 procedure TForm1.Button2Click(Sender: TObject);
 begin
   {現在輸入:}   Close;
   {程序於此完結}
 end;

現在再按 F12 來看看你的 Form1 視窗。現在該是儲存你的工作的時候了 (而且應該時常)!點選專案 > 另存專案 > 你取的檔名.pas (Project > Save Project As > your_selected_file_name.pas)。然後程式會再要求你儲存你的專案資訊,副案名為 .lpi。選一個不同的檔名,如果兩個取了同樣的檔名,你在編譯的時候會遇上 "重覆的識別子" 的錯誤 (請見此教學最後一章節 "Lazarus 檔案")。 你現在已經準備好可以開始編譯了。最簡單的方法就是在上方的主選單裡選 '執行 (Run)' 子選單,然後再按 '執行'。或是最直接地按 F9。程式會進行第一次的編譯並直接執行你的程式。

有幾個文字視窗會在你編譯的時候出現,顯示著你編譯時的所出現的訊息。但直到最後你的 Form1 視窗會重新出現,而且不帶有格子和標點。這就是你的應用程式的主畫面,並正等待你去按按鈕來與它互動。

試著去點標著 '按我' 的按鈕。你會注意到它變成了 '再按一次',但如果你再按一次,他還是一樣顯示 '再按一次'!

現在在按標著 '離開' 的按鈕,視窗會關閉,程式也隨之結束。然後又回到那個有格子與標點的 Form1 視窗,等待你再進一步的修改它。

改進你的程式

再一次開啟你剛儲存的專案。 在 Form1 視窗下點選 '按我' 按鈕 (Button1)。 再選物件檢視器裡的〔事件〕籤頁,點選方格右邊的省略符號,回到原始碼編輯器的相對地方。

如下編輯你的程式碼:

 procedure TForm1.Button1Click(Sender: TObject);
{使用一個標記物,設定它是1或是零}
 begin
   if Button1.tag = 0 then
   begin
     Button1.caption := '再按一次';
     Button1.tag := 1
   end else
   begin
     Button1.caption := '按我';
     Button1.tag := 0
   end
 end;

儲存你的工作,再重新編譯一次並執行。現在你左邊的按鈕就會交替地顯示訊息了。

接下來就完全看你自己了!

如果你偏好撰寫主控台下的 Pascal 程式 (比如說你正在上一堂 Pascal 的課要交作業用,或是為一個系統撰寫巨集指令),你也仍然可以使用 Lazarus 來撰寫、編譯並執行。有關於這個部份的開發,請見 主控台模式的 Pascal 的章節。

視窗編輯器

當你第一次執行起 Lazarus,會出現一系列不連續的,或說浮動著的視窗。

首先,桌面最上方會的標題會是 Lazarus 編輯 vXXXXXX - 專案1 (會隨著你目前的專案名稱變化)。這是控制你專案的主視窗,包含了主選單與元件面板。

LazMain GTK2.png

標題列下面的橫幅就是主選單 (Main Menu),有著一般常見的檔案,編輯,搜尋與檢視分類項目,下面還有幾個區塊來執行 Lazarus 的特定工作。 再下來的橫幅左邊是一些符號 (可以迅速執行你要的指令);而右邊就是元件面板。

在 Lazarus 編輯器視窗下左邊顯示的是物件檢視器視窗,而Lazarus 原始碼編輯器在右邊。那裡還有很多其他的小視窗,標著 Form1,並與 Lazarus 原始碼編輯器的視窗重疊著。如果無法立即找到他,可以按下 F12 在原始碼編輯器與表單之間切換顯示。表單視窗就是指你用來為你的應用程式建立圖形介面的地方,並直接與你撰寫中的 Pascal 原始碼關聯上。而物件檢視器的操作會在解說元件面板的時候一起做更多說明。最後,我們還有一個訊息視窗在螢幕的最下方,這裡 Lazarus 會顯示要告訴程式設計師訊息,例如你在編譯過程出了問題。

當你要新開一個新的專案 (或是當你第一次開啟 Lazarus),一份預設的的表單視窗會先建立好,上面會帶有許多格點用來幫助你定位在上面各似各樣的元件。而最上面一條細長的橫幅就是常見的縮到最小放到最大關閉視窗按鈕。點擊表單框框裡隨便一個物作,桌面左側的物件檢視器就會顯示出此物件的所有內容。

你在工作的過程中還有可能會看到一些其他的視窗:像專案檢視器,含有你的專案裡所擁有的檔案的詳細資料,讓你可對專案新加入或是刪除檔案。訊息視窗,用來顯示你的專案在編譯過程中出現的錯誤或任何訊息。如果你是在遠端執行 Lazarus,則你原來的這一端還是可以看到在編譯時出現的訊息。


主選單

主選單包含了以下的幾個項目: 檔案 (F) 編輯 (E) 搜尋 (S) 檢視 (V) 專案 (P) 執行 (R) 元件 (C) 工具 (T) 環境 (n) 視窗 (W) 協助 (H)

一般說來,選項都可以用滑鼠移過去後點擊選取,或是按鍵盤 Alt+F (將焦點移至主選單,如果原來還沒有),然後再按 Tab 在這幾個子選單裡交替移動,直到你要的子選單被反白為止。

檔案子選單 (File)

FileMenu.png
  • 新單元:建立一個新的單元檔 (Pascal 原始碼)。
  • 新表單:建立一個新表單:同時包含圖形視窗與相關聯的 Pascal 原始碼檔案。
  • 新增...:彈出一個選單 (擷圖),裡面有各種各樣的文件可供新增。
  • 開啟:彈出一個對話框,讓你可以瀏覽己經存在你的檔案系統裡的檔案來開啟。
  • 還原:完全放棄你對現在編輯的檔案所做的變更.把他還原到原來的狀態。
  • 開啟先前檔案:列出一份你先前開過檔案的清單,讓你選擇其中一個來開啟。
  • 儲存:使用該檔原來的檔案儲存檔案.如果他本來沒有取名,則為出現提示 (則同另存新檔)。
  • 另存新檔:讓你選另一個不同的檔名來儲存檔案。
  • 儲存全部:儲存所有編輯器開啟的檔案,而非只有目前編輯中的。
  • 關閉:關閉目前的檔案,並提示以儲存變更。
  • 關閉所有編輯的檔案:關閉所有開啟在編輯器裡的檔案,並提示儲存。
  • 清理目錄:用對話框的模式提供給你一些可自訂的篩選器,讓你可以移除一些目錄裡的檔案。例如 .bak 這種檔或舊的 Delphi 專案殘骸。
  • 列印:使用系統的印表機列印所選取的檔案,若您不是使用 Windows,選單裡預設並沒有任何項目。你會需要先安裝 $Lazdir/components/printers/design/printers4lazide.pas 這份套件再重新編譯 Lazarus IDE。
  • 重新開啟:重開 Lazarus,當你感到你的 Lazarus 已經變的一團亂的時候很有用!
  • 離開:退出 Lazarus,並提示您是否已儲存所有你編輯的檔案。

編輯子選單 (Edit)

EditMenu.png
  • 復原:復原您上一動的編輯,讓編輯器裡回到上一個動作之前的狀態。
  • 重做:重新進行上一步已經被你復原回去的動作。
  • 剪下:移去您選取的文字(或任何項目)並放置到剪貼簿裡。
  • 複製:建立一份所選取的文字的副本,留有原來的文字並將副本放到剪貼簿裡。
  • 貼上:將剪貼簿裡的內容置放到你游標目前的位置。如果你目前的游標選取了某些字,則剪貼簿裡的內容會取代這些被選取的字。
  • 選取文字縮排:將選取的文字向右移動一個距離,可於[環境]->[編輯器選項]->[一般]->[區塊縮排]設定。這在你撰寫 Pascal 原始碼時用於統一格式,區分區塊結構時很有用。
  • 選取文字取消縮排:移除一個階層的縮排,將文字向左移動一個區塊固定的距離。
  • 關閉選取文字:彈出一個選單,裡面有幾個選項可以讓你關閉選取文字裡,符合條件的敘述句 (begin ... end; try ... except; try ... finally; repeat ... until; { ... } 等等)。
  • 選取文字變大寫:轉換選取的文字成大寫。
  • 選取文字變小寫:轉換選取的文字成小寫。
  • 選取文字跳格轉空白將選取的文字裡作任跳格字元轉換成固定數量的空白字元,數量可於[環境]->[編輯器選項]->[一般]->[跳格寬度]裡設字。空白字元數量並非固定的,但至少一定會填滿目前跳格字元的寬度。
  • 選取文字斷行若有任何選取文字裡單行有超過 80 個字元(或於[環境]->[編輯器選項]->[顯示]->[右邊界]設定寬度)的情況,則將該行在邊界的地方自動斷行並於下一行繼續。
  • 註解選取文字: 將選取的文字每一行插入 // 以轉成註解
  • 選取文字取消註解:移除註解標記。
  • 排序選取文字:將行 (或字或段落) 依字母排列;可選升冪或降冪,區不區分大小寫。總之不管有無意義你覺得有需要就可以這麼做。
  • 選取:可以讓你選取一個區段的文字。選項有選取全部,選取括號,選取段落或行等等。
  • 從字元表插入字元:讓你可以插入一個鍵盤裡沒有的符號或是外國字,從彈出的字元表選單裡去選。
  • 插入文字: 彈出一個選單,讓人可以插入一些標準的文字,如 CVS 關鍵字 (Author, Date, Header 等等) 或是 GPL 警告,使用者名稱或是目前日期與時間。
  • 程式碼自動完成:完成目前游標所在處的程式碼。會自動區分前後文的文意以節省你的時間。例如;它會自動加入 private 變數,擷取並設定方法的內容並直接加入方法本體,以完成整個類別。在指派變數 (如 i:=3;) 的敘述裡他會自動加入變數的宣告,在定義程序裡,他會自動加入程式的本體。在觸發事件的指派裡 (OnClick:=) 它則會自動加入方法的定義與方法本體。參見Lazarus IDE 工具.
  • 建立程序:利用選取的文字 (一段敘述或一連串的敘述) 來建立一個新的程序。

搜尋子選單

SearchMenu.png
  • 尋找:功能幾乎與所有圖形介面的文字編輯器一樣:一個彈出的對話框可以輸入要搜尋的字串,有區分大小寫的選項,完整字辭搜尋,起點,命名空間和搜尋方向。
  • 尋找下一個,尋找上一個:利用上次輸入的字串,向指定的方向再次搜尋。
  • 在檔案裡尋找:在檔案裡搜尋字串:彈出對話框,選項有[所有開啟的檔案],[所有專案裡的檔案],[所有目錄];允許建立遮罩以指定檔案類形。
  • 取代:和尋找類似;彈出對話框讓你可以同時輸要搜尋的字串和要取代成的字串,然後有區分大小寫,搜尋方向等等的選項。
  • 漸進式尋找:搜尋動作會依你輸入字串一步一步搜尋,例如你選取[漸進式尋找]後,你先按下 "l" ,所有第一個字母是 "l" 的字會被標明出來,然後你若再輸入 "a",則編輯器會接著尋找 "la"。
  • 移至:移動編輯中的游標到指定的行號。
  • 跳回:跳到上一個位置。每一次跳躍到錯誤或是宣告處 IDE 會儲存目前原始的位置,這個功能可以讓你再依記錄跳回來。
  • 向前跳:跳到下一個位置,復原回上一次跳躍。
  • 新增跳躍記錄點:加入目前的位置到跳躍記錄中。
  • 檢視跳躍記錄點:檢視跳躍點的清單。(更多)
  • 跳到下一個錯誤, 跳到上一個錯誤:跳到到上一個或下一個在原始碼檔裡被回報有錯誤的地方。
  • 設定書籤:標記目前游標所在行成可以利用 (自由使用) 的書籤並加上編號,然後加入到書籤清單裡。注意彈出的選單 (加原始碼檔案裡在適當的行裡點右鍵取得) 裡書籤的範圍很廣,可以指定編號找到書籤,或是允許使用者指定編號跳到書籤處,而不單只是上一個下一個。
  • 跳到下一個書籤, 跳到上一個書籤:依順序跳到上一個或下一個書籤。
  • 尋找程式碼區塊的其他結尾:如果目前處在 begin 處,找到相對應的 end 處,反之亦然。
  • 尋找程式碼區塊的開始:移動到目前游標所在的程序或函式的 begin 處。
  • 尋找游標處的宣告:為目前選取的識別子找到它的宣告處。位置有可能再同一個檔案裡,也可能在另一個編輯器開啟的檔案裡;但若是未開啟的檔案,程式則會自動開啟該檔。(像一個程序或函式在 classesh.inc 裡宣告後,程式則將之開啟)。(更多)
  • 開啟游標處的檔案:開啟游標選取其檔名的檔案。對於 Include 檔的搜尋或是取得專案裡包含的單元特別有用。
  • 移到含括檔指示處:若游標指到的檔名是被 Included 在其他的檔案裡,則移至 Include 所指名稱的檔案裡。
  • 尋找參照的識別子:建立一份列出在目前檔案裡,或所有依附於目前專案裡所有識別子的清單。
  • 識別子重新命名:可以讓開發者為識別子重新命名。對話框提示開發者看是要針對目前撰寫中的檔案裡改名就好,還是整個專案的,或所有已開啟檔案的都要改。甚至於註解文字裡的識別子都會一起改掉。此功能適用於當編譯時有識別子已經存在了,或你單純想為識別子重新取個名字。
  • 程序清單:建立一份目前檔案裡所有程式與函式的清單,並加註他們宣告處所在的行號。

檢視子選單

ViewMenu.png

控制螢幕裡各個視窗與面版的一些顯示。

  • 物件檢視器:這個視窗通常都一直佔據在你桌面的左方,顯示您表單的特徵。滑鼠選的所有表單裡的物件,詳細內容都會在物件檢視器裡顯示。上半的面版有一個專案的樹狀圖,分列出表單裡的元件供選取。這和物件檢視器所提供的是一致的。主要的下半面版顯示有兩個籤頁,內容事件。選擇內容會顯示的特徵有如命名,顏色,字型,尺寸等:這部份分成兩欄,左半是寫內容名稱,右半則是與內容關聯的值。選擇事件會顯示兩欄:左半一樣是事件名稱,如關聯到元件的 MouseClick 或 KeyDown,而右邊就是事件發生後要進行的動作。如果沒有定義任何動作,按一下刪節號
    ...
    會跳回原始碼編輯器,游標會停在一個空的程序裡,等待你把程式內容寫進去。
  • 原始碼編輯器: The main window in which source code is edited. Its behaviour is very like that of most other graphical text editors, so that the mouse can move the cursor over the displayed text, and clicking with the left mouse button while dragging the mouse will select and highlight text. Right clicking with the mouse displays a pop-up menu, it includes the usual Edit Cut, Copy or Paste functions, Find Declaration and Open File at Cursor. The top of the 原始碼編輯器 window has a number of tabs, corresponding to the files that are open for the current project; clicking on any tab makes that file visible, and you can move easily from file to file, copying and pasting between files and performing most of the normal editing functions. The 原始碼編輯器 performs color syntax highlighting on the code, with different colors for punctuation marks, comments, string constants etc. It will also maintain the level of indentation from line to line as you type in code, until you change the indentation. The function and appearance of the 原始碼編輯器 are very configurable from the Main Menu by selecting Environment -> Editor options and then selecting one of several tabs in the pop-up dialog box.
  • Code Explorer: A window usually placed on the right of the Desktop which displays, in tree form, the structure of the code in the current unit or program. It usually opens with just the Unit name and branches for Interface and Implementation sections, but clicking on the
    +
    box to the left of any branch will open up its sub-branches or twigs, in more and more detail until individual constants, types and variables are displayed as well as procedure and function declarations. If you change the file displayed in the main 原始碼編輯器 window, you need to click on the Refresh button of the Code Explorer to display the structure of the new file.
  • Units...: Opens a pop-up dialog window with a list of the unit files in the current project.Clicking with the mouse on a filename selects that file; click on Open to display that file in the 原始碼編輯器. Checking the Multi box allows several files to be selected simultaneously, and they will all be opened in the 原始碼編輯器 (but only one at a time will be displayed). This Menu Option is rather like the Project -> Project Inspector option, but only displays the list of Unit files and allows them to be opened.
  • Forms...: Opens a pop-up dialog window with a list of the Forms in the current project, and allows the selection of one or more of them for display.
  • View Unit Dependencies: Opens a pop-up dialog window that shows, in a tree-like manner, the structure of dependencies of the currently open unit file. Most of the files listed as dependencies will have their own
    +
    boxes, which allow the dependencies of the individual files to be explored, often in a highly recursive manner.
  • Toggle form / unit view F12: Toggles whether the 原始碼編輯器 or the current Form is placed on the top layer of the Desktop, and given focus. If the 原始碼編輯器 has focus, then you can edit the source code; if the Form is given focus, you can manipulate the components on the desktop and edit the appearance of the Form. The easiest way to toggle the display between Editor and Form is to use the F12 key on the keyboard, but the same effect is achieved by selecting this option on the Main Menu.
  • Messages: A window that displays compiler messages, showing the progress of a successful compilation or listing the errors found.
  • Search Results: A window that displays the results of find in files.
  • Debug windows: Opens a pop-up menu with several options for operating and configuring the Debugger. See below where the debugger is described.

The Project sub-menu

ProjectMenu.png
  • New Project: Create a new project. A pop-up dialog window appears offering a choice of types of project to create.
  • New Project from file: A Navigation dialog window appears, alowing selection of a file from which to create a new project.
  • Open Project Open a project which has already been created and saved. A navigation dialog appears with a list of Lazarus Project Information (.lpi) files from which a project may be chosen.
  • Open Recent Project: Displays a pop-up list of recent projects on which you have been working, and allows selection of one of these.
  • Save Project: Similar to File -> Save: all the files of the current project are saved; if they have not previously been saved, there is a prompt for filename(s)- similar to Save Project As...
  • Save Project As...: Prompts for filename to save project. A default filename of Project1.lpi is offered, but you should choose your own filename. Lazarus will not permit you to use the same name for the Project file and the Unit File (see below).
  • Publish Project: Creates a copy of the whole project. If you want to send someone just the sources and compiler settings of your code, this function is your friend. A normal project directory contains a lot of information. Most of it is not needed to be published: the .lpi file contains session information (like caret position and bookmarks of closed units) and the project directory contains a lot of .ppu, .o files and the executable. To create a lpi file with only the base information and only the sources, along with all sub directories use "Publish Project". In the dialog you can setup the exclude and include filter, and with the command after you can compress the output into one archive. See Lazarus IDE Tools
  • Project Inspector: Opens a pop-up dialog with a tree-like display of the files in the current project. Allows you to add, remove or open selected files, or change options of the project.
  • Project Options...: Opens a pop-up dialog window with tabs for setting options for Application (Title, Output Target file name), Forms (allowing you to select among the available forms, make them Auto-create at start of application) and Info (specifying whether editor information should be saved for closed files, or only for project files).
  • Compiler options ...: (Recently moved here from the Run Menu). Opens a multi-page tabbed window which allows configuration of the compiler. Tabs include Paths which allows definition of search paths for units, include files, libraries etc, as well as allowing choice of widget type for the forms (gtk, gnome, win32); Parsing which allows choice of rules for parsing source programs, Code which allows choice of optimisation for faster or smaller programs, choice of target processor, types of checks, heap size etc; Linking allowing choice of whether or how to use debugging, static or dynamic libraries, and whether to pass options through to the linker; Messages to define what type of messages should be generated during error conditions; Other which allows decision to use default configuration file (fpc.cfg) or some other file; Inherited which shows a tree structure diagram to indicate how options have been inherited from units already incorporated; Compilation which allows definition of commands to be executed before or after the compiler is launched and can allow use of Make files.
  • Add editor file to Project: Add the file currently being edited to the Project
  • Remove from Project: Gives a pop-up menu of files available for removal from project.
  • View Source: No matter which file you are editing, takes you back to the main program file (.lpr)or the main .pas file if there is no .lpr.
  • View ToDo List:Opens a dialog box with a list of ToDo items associated with this project. This will list any ToDo comments in your project (lines commencing //TODO), and any others in the Lazarus units you have used. You need to Refresh the ToDo items in the dialog (using arrow symbol button of toolbar) before new 'ToDos' appear. The first column of the ToDo list contains numbers you have allocated to your ToDo comments; a simple //TODO comment will appear as a zero, but a comment of //TODO999 (for example) will place the number 999 in the first column. Remember there should be no spaces on the line before //TODO and ToDo comments added after the last save will not be shown!

The Run sub-menu

RunMenu.png
  • Build: Causes Lazarus to build (ie compile) any files in the project that have been changed since the last build.
  • Build all: Builds all files in the project, whether or not there have been any changes.
  • Abort build: Stop the build process once it is running - either you have remembered that you did something silly and want to stop the build, or the system seems to be taking far too long and something is obviously wrong.
  • Run: This is the usual way to launch the compiler and, if compilation is successful, to start execution of the application. What actually happens is that Lazarus saves a copy of your files, then starts the compiler and linker, then begins execution of the final linked binary program.
  • Pause: Suspend execution of the currently running program. This may allow you to inspect any output that has been generated; execution may be resumed by selecting Run again.
  • Step into: Used in conjunction with the debugger, causes execution of the program one step at a time up to a bookmarked point in the source.
  • Step over: Causes stepwise execution up to the statement marked, then skips the marked statement, and continues execution at normal speed. Useful in trying to isolate a statement that introduces a logical error.
  • Run to cursor: Causes execution at normal speed (ie NOT one statement at a time) until the statement is reached where the cursor is located; then stops. Resume execution at normal speed by selecting Run.
  • Stop: Cease execution of the running program. Cannot be resumed by selecting Run; this will start the program again from the beginning (re-compiling if necessary).
  • Run Parameters: Opens a multi-page pop-up window which allows command-line options and parameters to be passed to the program to be executed; allows selection of display to run program (eg a remote X terminal may be used in Linux); some system Environment variables may be overridden.
One very important use of this sub-menu is to activate a terminal window in which conventional Pascal console input/output is displayed. If you are developing a console-mode Pascal program (ie one that doesn't use the Graphical User Interface with its forms, buttons and boxes) then you should check the box for "Use launching application". The first time you do this and try the Compile/Run sequence, you will probably get a rude message to say
"xterm: Can't execvp /usr/share/lazarus//tools/runwait.sh: Permission denied".  
If this happens, you need to change the permissions on the appropriate file (for example using chmod +x filename, or using the Windows utility for changing permissions); you might have to do this as root. After this, each time you launch you program, a console box will appear and all your text i/o (readln, writeln etc) will appear in it.
After your program has finished execution, a message "Press enter" appears on the screen. Thus any output your program generated will remain on the screen until you have had a chance to read it; after you press 'enter' the console window closes.
Note: as for the current version, there is no prepared console command for Windows users. Until the Lazarus team adressess that, the following line should work (on WinXP -- someone please update for other Windowses)
C:\Windows\system32\cmd.exe /C ${TargetCmdLine}
See the separate tutorial on Console Mode Pascal programming.
  • Reset debugger: Restores the debugger to its original state, so that breakpoints and values of variables etc are forgotten.
  • Build file: Compile (build) just the file that is currently open in the Editor.
  • Run file: Compile, link and execute just the currently open file.
  • Configure Build + Run File: Opens a multi-page tabbed window with options to allow for build of just this file when Build Project is selected, allows selection of the working directory, the use of various Macros, etc. Then Builds and Runs the file.
These last three options enable you to open (and maintain) a test project. Use File -> Open to open an .lpr file, pressing cancel on the next dialog to open this file as "normal source" file.

The Package sub-menu

  • Open Package: Displays a list of installed packages, with an invitation to open one or more of them, or to select various general or compiler options.
  • Open Package File: Open one of the files in the selected package.
  • Open Recent Package: Open a package that was opened recently.
  • Add Active Unit to Package: Place the unit file (currently in the editor) into a package.
  • Package Graph: Displays a graph showing the relationships of the packages currently being used (if you aren't using any other packages, the Lazarus package and the FCL and LCL will be displayed).
  • Configure custom components: If you have created some components, allows you to configure them.

The Tools sub-menu

ToolsMenu.png
  • Configure custom tools: Allows the user to add various external tools (usually macros) to the toolkit
  • Quick syntax check: Perform a quick check of the syntax in your source file without actually compiling anything. Essential step in developing long or complicated programs, where you don't want to waste time compiling if the code is wrong.
  • Guess unclosed block: useful utility if you have a complex nested block structure and you have left out an 'end' somewhere
  • guess misplaced IFDEF/ENDIF: useful if there is a complex or nested macro structure and you think you have left out an ENDIF directive
  • Make resource string: Makes the selected string a resource string by placing it in the resourcestrings section. An advantage of resource strings is you can change them without the need to recompile your project!
  • Diff: Allows comparison between two files (or, usually, two versions of the same file) to find differences. Options to ignore white space at beginning or end of lines or differences in line termination: CR+LF versus LF). Useful for checking if there have been changes since last CVS update etc.
  • Check LFM file in editor: Allows inspection of the LFM file which contains the settings that describe the current form
  • Convert Delphi unit to Lazarus unit: Helps in porting Delphi applications to Lazarus; makes the necessary changes to the source file. See Lazarus For Delphi Users and Code Conversion Guide.
  • Convert DFM file to LFM: For porting from Delphi to Lazarus: converts the Form Description files from Delphi to Lazarus. See Lazarus For Delphi Users and Code Conversion Guide.
  • Build Lazarus: Launches a re-build of Lazarus from the most recently downloaded or updated SVN files. Hit the button and sit back to watch it happen! (track the process on your Messages window).
  • Configure "Build Lazarus": Allows the user to determine which parts of Lazarus should be re-built, and how. For example, you could select to have just the LCL re-built, or to have everything except the examples built; you can select which LCL interface to use (ie which set of widgets), and you can select the target operating system and specify a different target directory.

Standard packages add the following menu items:

環境子選單

EnvironmentMenu.png
  • 環境選項:顯示一個代多個標籤頁的視窗
    • 檔案 - allowing the user to specify path to default directory, compiler, source directory and temporary directory for compilation;
    • 桌面 - options for Language, Auto save behaviour, saving desktop properties, hints for component palette and speed buttons;
    • 視窗, to allow specification of size and behaviour of the various windows;
    • 表單編輯器 - choose colours for editing forms;
    • 物件檢視器 - choose colour and height of items;
    • 備份 - specify how to backup files when editing;
    • 命名 - specify what extension to use in naming pascal files ('.pp' or '.pas'), whether to save files with names in lowercase, whether to perform auto-delete or auto-rename.
  • 編輯器選項: Multi-page window, with tabs for
    • 一般 - determines behaviour like auto-indent, bracket highlighting, drag-drop editing, scrolling, syntax highlighting, showing hints, size of block indent and tabs, limit of Undo;
    • 顯示 - options for showing line numbers, presence of gutters, size and type of font for editor, and contains a preview panel showing the colours of the various syntax features such as comments, directives, punctuation, errors and breakpoints;
    • 按鍵對應 - options to select Lazarus or Turbo Pascal scheme;
    • 顏色 - allows choice of colour scheme for text features, for a number of language types such as Object Pascal, C++, Perl, HTML, XML and shell scripts. It shows preview panel again (for whichever language is selected);
    • Code Tools - allows selection of features like Identifier Completion, tooltips, specification of template file names, specific templates for code completion.
  • Debugger Options: Multi-page window with tabs for
    • General - choose debugger: none, GNU debugger (gdb) or gdb through SSH, specify search paths for debuggers,and specific options for chosen debugger;
    • Event log - specify whether to clear log on run, and which messages to display;
    • Language Exceptions - select which exceptions can be ignored;
    • OS Exceptions - allows user to add certain signals which apply to current operating system (not implemented).
  • Code Tool Options: Multi-page window, tabs for
    • General - Allows entry of additional source search paths, specify Jumping Method;
    • Code Creation - determines whether created code is added before or after certain features;
    • Words - determines whether Pascal keywords are to be entered in upper or lower case, or as Capitalised Words;
    • Line Splitting - establish rules about where lines are allowed to be split (before or after punctuation, after keywords etc);
    • Space - decide whether a space is to be added automatically before or after certain syntactic features such as keywords or punctuation marks.
  • Code Tools Defines Editor: Here you can see all IDE internal definitions to parse sources. You will see all the defines, unit, source, include paths for all source directories. Beginning with the settings of the current FPC, the defines for the Lazarus Source directory, all package directories and project directories.

Most of these settings are auto generated and read only.


  • Re-scan FPC Source directory Looks through the directory again. Lazarus uses the fpc sources to generate correct event handlers and while looking for declarations. If somebody changes the directory in the environment options, then this directory is rescanned, to make sure Lazarus uses the version stored in that location. But if this directory has changed without Lazarus noticing, then you may get some errors when designing forms or doing "Find declaration". If you get such an error, you can do two things:
    1. Check the fpc source directory setting in the environment option.
    2. Re-scan FPC source directory.

The Windows sub-menu

WindowsMenu.png

Contains a list of the currently opened files and the available windows such as 原始碼編輯器, 物件檢視器 and Project Inspector. Clicking on the name of one of the windows brings it to the foreground and gives it focus.

The Help sub-menu

At present this has three selections:

  • Online Help which at present opens a browser window that contains a picture of the running cheetah and a few links to the Lazarus, Free Pascal and Wiki websites
  • Reporting a bug opens the wiki page, which describe the bug reporting procedure
  • Configure Help which opens a pop-up menu with options to select viewers and databases from which to read Help information. This option allows the user to specify either the on-line documents section of the Lazarus-CCR website, some other website containing the documents, or a local store for the documentation (this would eventually become the default, when the Help system is fully developed).

At present by default, if you place your Editor cursor over any keyword from the Free Pascal Components Library FCL, the RunTime Library RTL or the Lazarus Components Library LCL, and then press F1 you will be taken by your default browser to the appropriate definition on the website. Be aware that your browser may be located on another desktop on your machine (eg in Linux), and you may not see the information immediately; of course if you are not connected to the internet you cannot get this information.

There are alternative help options which gives the end-user off-line help. For example, if you have a copy of Kylix, you can reuse the help files supplied with it, inside Lazarus IDE. See the Adding Kylix Help page for details.

  • About Lazarus Displays a pop-up box with some information about Lazarus.

Eventually there will be a full on-line Help service, with information about Pascal syntax, the use of the IDE, how to use, modify or create Components, and hints on how to perform certain tasks. This part of the Documentation section (the thing you are currently reading) represents the beginning of the process. We need contributions from anyone who feels able to provide them: the WiKi is very easy to edit.

The Button bar

A small toolbar area on the left of the main editor window, just below the Main Menu and to the left of the Component Palette, contains a set of buttons which replicate frequently-used Main Menu selections:

New unit, Open (with a down-arrow to display a drop-down list of recently used files), Save, Save all, New Form, Toggle Form/Unit (ie show either form or source code of Unit), View Units, View Forms, Run (ie compile and Run), Pause, Step Into, Step over (the last two are Debugger functions).

The Component Palette

A Tabbed toolbar which displays a large number of icons representing commonly used components for building Forms.

Each tab causes the display of a different set of icons, representing a functional group of components. The left-most icon in each tabbed group is an obliquely leftward-facing arrow, called the Selection Tool.

If you allow the mouse cursor to hover over any of the icons on the Component Palette, without clicking on the icon, the title of that component will pop-up. Note that each title begins with a 'T' - this signifies 'Type' or more accurately 'Class' of the component. When you select a component for inclusion in a form, the Class is added to the type section of the interface part of the Unit (usually as part of the overall TForm1), and an instance of that class is added to the var section (usually as the variable Form1). Any Methods that you design to be used by the Form or its Components (ie Procedures or Functions) will be placed in the implementation part of the Unit.


How To Use the Palette

To use the Palette, there must be an open form on view in the editor (if there isn't one, select File -> New Form). Click on the icon in the appropriate tab of the Palette for the component you want to use, then click on the Form, near where you want the component to appear. When the desired component appears, you can select it by clicking with the mouse. Once selected on the form, the object is also selected in the 物件檢視器 window, where you can edit its properties and events.

Adjustments to the visual appearance of an object can be made either by altering the picture itself on the Form using the mouse, or by changing the relevant Property in the Object Editor for that component.

If you install additional components, either those you have written yourself, or some coming as a package from some other source, then extra tabs with the relevant icons will appear in your Component Palette. These new components can be selected and used on your forms in the same way as those supplied by default.

In the following list of the Components, you will find links to files that contain descriptions of the Units in which they are found. If you want to find out about the properties of a particular component, it is often worth looking at the Inheritance of that component and then inspecting the properties of the base type from which it is derived. For example, to understand TMaskEdit it is also useful to examine TCustomMaskEdit.

Standard

(See Standard tab for components description)

Component Palette Standart.png
Frequently used components: TMainMenu, TPopupMenu, TButton, TLabel, TEdit, TMemo, TToggleBox, TCheckBox, TRadioButton, TListBox, TComboBox, TScrollBar, TGroupBox, TRadioGroup, TCheckGroup, TPanel, TActionList

Additional

(See Additional tab for components description)

Component Palette Additional.png
More, often-used components: TBitBtn, TSpeedButton, TStaticText, TImage, TShape, TBevel, TPaintBox, TNotebook, TLabeledEdit, TSplitter, TTrayIcon, TMaskEdit, TCheckListBox, TScrollBox, TApplicationProperties, TStringGrid, TDrawGrid, TPairSplitter, TColorBox, TColorListBox, TChart

Common Controls

(See Common Controls tab for components description)

Component Palette Common Controls.png
TTrackBar, TProgressBar, TTreeView, TListView, TStatusBar, TToolBar, TUpDown, TPageControl, TTabControl, THeaderControl, TImageList, TPopupNotifier

Dialogs

(See Dialogs tab for components description)

Component Palette Dialogs.png
TOpenDialog, TSaveDialog, TSelectDirectoryDialog, TColorDialog, TFontDialog, TFindDialog, TReplaceDialog, TOpenPictureDialog, TSavePictureDialog, TCalendarDialog, TCalculatorDialog, TPrinterSetupDialog, TPrintDialog, TPageSetupDialog

Several useful Dialog procedures or functions don't appear on the Palette, but are easily used as direct calls from your source program.

For several good examples of the use of Components see the $LazarusPath/lazarus/examples subdirectory of your source installation. Many of the programs show how to use dialogs and other components directly without using the IDE and component palette or having a separate form definition file: all the components are fully and explicitly defined in the main Pascal program. Other example programs make full use of the IDE.

Remember to open these examples as projects, with the .lpi file. Opening the .pas source code file and hitting RUN will just append this source file to whatever project you opened last.

Some examples don't work straight away: you may need to play about with paths and permissions of files or directories. If you want to compile any of the examples, make sure that you have read/write/execute permissions for the files and directories, or copy the files to a directory where you do have the appropriate permissions.

Try running the 'testall' program to see a menu of the available components together with small example test forms for most of them; then inspect the code to find out how they work!

Misc

Component Palette Misc.png
TColorButton, TSpinEdit, TFloatSpinEdit, TArrow, TCalendar, TEditButton, TFileNameEdit, TDirectoryEdit, TDateEdit, TCalcEdit, TFileListBox, TXMLPropStorage, TIniPropStorage, TBarChart, TButtonPanel, TIDEDialogLayoutStorage

Data Controls

Component Palette DataControls.png
Data-aware components, which largely replicate the Standard and Additional groups but are applicable to Databases: TDBNavigator, TDBText, TDBEdit, TDBMemo, TDBImage, TDBListBox, TDBComboBox, TDBCheckBox, TDBRadioGroup, TDBCalendar, TDBGroupBox, TDBGrid

Data Access

Component Palette DataAccess.png
TDatasource, TMemDataset, TSdfDataSet, TFixedFormatDataSet, TDbf

System

Component Palette System.png
TTimer, TIdleTimer, TLazComponentQueue, THtmlHelpDatabase, THtmlBrowserHelpViewer, TProcessUTF8, TAsyncProcess, TProcess, TSimpleIPCClient, TSimpleIPCServer, TXMLConfig, TEventLog

SynEdit

Component Palette SynEdit.png
SynEdit is an advanced multi-line edit control, which is integrated into the Lazarus. It is the code editor of the Lazarus IDE and is available in the directory "lazarus/components/synedit". It supports Syntax Highlighting, code completion, code folding and includes exporters for html, tex and rtf. It is a fully custom drawn component, meaning that it doesn't wrap native controls of each platform and that no external library is required; this make SynEdit a crossplatform component. Note that the SynEdit available with Lazarus is a fork of the original SynEdit for Borland Delphi, Kylix and C++Builder which can be found in synedit at sourceforge. : TSynEdit, TSynAutoComplete, TSynExporterHTML, TSynMacroRecorder, TSynMemo, TSynPasSyn, TSynFreePascalSyn, TSynCppSyn, TSynJavaSyn, TSynPerlSyn, TSynHTMLSyn, TSynXMLSyn, TSynLFMSyn, TSynUNIXShellScriptSyn, TSynCssSyn, TSynPHPSyn, TSynTeXSyn, TSynSQLSyn, TSynPythonSyn, TSynVBSyn, TSynAnySyn, TSynMultiSyn

How to use Common Controls

The Units StdCtrls, ComCtrls and ExtCtrls contain definitions and descriptions of many of the most commonly used controls for constructing Forms and other Objects in Lazarus Applications.

Many of the final target controls that the application developer wants to use, such as TButton, TMemo, TScrollBar etc, have a corresponding ancestor class such as TCustomButton, TCustomMemo or TCustomScrollBar. Several of the properties and methods relevant to the final target control are defined (and explained) more fully in the TCustomXXX class, and are inherited by the final target control.

If you drop a component on the form editor you don't need to add code explicitly to create it. The component is automatically created by the IDE together with the form, and destroyed when the form is destroyed. However, if you create the component yourself by code don't forget to free it when it is no longer needed.

Ways to Set Properties

If you place a component on the Form Designer and look at the 物件檢視器, you can observe the properties change as you move the component around.

For example, if you place a button (TButton) on the form, click on it to select it, then move it around the form with the mouse, you can watch the values of Top and Left change in the 物件檢視器 to reflect the new position. If you use the object's re-sizing bars to adjust its size, you can watch the Height and Width properties change as well.

On the other hand, by using the 物件檢視器, you can select the value associated with a property such as height, and type in a new value; you can watch the size of the object on the form change to reflect the new value.

You can also explicitly change the properties of the object in code by typing (in the appropriate Implementation section of the 原始碼編輯器), for example

Form1.Button1.Height := 48; If you type this new value into the 原始碼編輯器 and then look back at the Form Designer, you will see that the button on the Form has taken the new size. The new value will also be shown in the 物件檢視器.

In summary, there are usually about three different ways to determine each property of an object:

  • by using the mouse on the form,
  • by setting the values in the 物件檢視器,
  • or explicitly by writing code in the editor.

Common Properties

The components defined in these Units have several properties that are common to most of them, and other properties that are specific to the individual components. We shall describe the most common ones here. Unusual or control-specific properties will be described for the individual controls.

Additional Help can always be obtained by selecting a property or keyword, in either the 物件檢視器 or the 原始碼編輯器, and pressing F1. You will be taken by your Help browser to the appropriate page in the documentation.

If the description of a property on that page is insufficient, you can navigate to the corresponding description in the ancestor classes, by selecting the links in the Inheritance listing or by selecting the ancestor Type in the declaration of the object.


Some commonly listed properties
PropertyMeaning
Action The main action or event associated with the object. For example selecting an 'Exit' Button might cause the 'Close' action
Align Defines the way in which an object is to be lined up with the parent object. Possible values are alTop (placed at the top and using the full available width), alBottom, alLeft (placed at the left and using the full available height), alRight. alNone (place anywhere on parent control) or alClient (takes all available space next to controls aligned to top, bottom, left or right)
Anchor Used to keep a control a certain distance from the defined edges of a parent control, when the parent is resized. For example [akBottom, akRight] will keep the control a fixed distance from the bottom right corner.
AutoSelect When True, an editing control will select all its text when it receives focus or when the Enter key is pressed.
AutoSelected True indicate that the edit or combobox control has just performed an AutoSelect operation so that subsequent mouse-clicks and keystrokes proceed normally without selecting the text.
BorderSpacing The space around the edge between an Anchored control and its parent.
Caption The text that is displayed on or near the control; it should preferably give some clue as to the function of the control, or an instruction such as 'Close' or 'Execute'. By default Caption is set to be the same as the 'Name' property, and the application programmer should substitute meaningful text instead of the default values.
CharCase Indicates how text is displayed in a text editing control: Normal (retaining the case of the letters typed by the user), converted to uppercase, or converted to lowercase
Constraints Sets the minimum and maximum sizes for a control. If a control is resized the new dimensions are always within the ranges given here. You should take care when setting these options that they do not conflict with the Anchors and Align settings.
Color The Colour to be used to draw the control or to write the text it contains.
Enabled A Boolean property to determine whether or not a control is capable of being selected and performing an action. If it is not Enabled, it is often Grayed out on the Form.
Font The Font to be used for writing the text associated with the control - either the caption or label, or the text-strings contained within the control. The entry on the 物件檢視器 usually has a (+) box on the left, and selecting this box reveals further options such as character set, colour and size.
Hint A short piece of informative pop-up text that appears if the mouse-cursor hovers over the control.
Items The list of 'Things' that the object contains, such as a group of images, a series of lines of text, a number of actions in an actionlist, etc
Lines An array of strings, containing the textual data in controls with more than a single line of data, such as an Edit-Box or a Combo-Box. The array is zero-indexed, ie the lines are numbered [0..numLines-1]
Name The identifier by which the control is known in the program. The IDE gives it a default name based on the underlying type, for example successive instances of TBitButton would be named Form1.BitBitton1 and Form1.BitButton2; it is up to the application programmer to give them more meaningful names such as ExitButton or OKButton. By default the Name of the control is applied to the Caption for the control, but the text of the Caption may be changed separately.
PopUpMenu A window containing context-sensitive menu information that pops up when the right mouse button is clicked on the object.
Position (or Top, Left) Determines where the control is located on the parent form or window
ReadOnly Boolean property which, if True, signifies that the contents of the control can be read by the user or the calling routine, but cannot be written or changed.
ShowHint Allows a small window containing a context-sensitive Help or other description to be displayed when the mouse cursor 'hovers' over the control.
Size (or Height and Width) The dimensions of the control
Style The options available for Style depend upon the sort of Control being considered: for instance the Style may be defined by TFormStyle, TBorderStyle, TButtonStyle etc.
TabOrder Integer defining where in the sequence of tabs on the Form this control is to lie
TabStop Boolean property which if True places this control in the sequence of objects that the user can reach by successively pressing the Tab key
Text The String of Text that represents the actual data that this control contains. Applies particularly to Text, Memo and StringList types of object. Most of the editing operations (such as Select, Clear, Cut, Copy) are performed in this part of the object, which holds the actual string being edited. If the control contains more than a single line of text, for example TMemo or TComboBox, then the textual elements are arranged as an array of strings (zero-indexed, ie numbered from [0..numLines-1]) in Lines.
Visible If true, the object can be seen on the Form; if False, object is hidden
WordWrap Logical flag to show whether or not word-wrap is enabled, ie if a word comes close to the end of a line and is going to be too long for the line, it is wrapped down to the next line.


Event Actions

Many actions are commonly listed in the 'Events' tab of the 物件檢視器. If you select an entry in the list, a ComboBox appears with a DropDown list showing any actions that have aleady been defined, and allowing you to choose one to be associated with this event. Alternatively you can select the ellipsis (three dots ...) and you will be taken to an area of the 原始碼編輯器 where you can begin typing your own action instructions for the selected event.

While a large number of events is available for any given control, in practice it is only necessary to populate a few of them. For most controls, it is sufficient to provide coding for 'OnClick'; for more complex controls it may be necessary also to provide for 'OnEntry' (when the mouse cursor enters the Control and gives it focus) and 'OnExit' (when the mouse cursor leaves the Control; or you may need to write an event handler for 'OnChange' or 'OnScroll', depending on the nature of the particular control with which you are dealing.

The pop-up menu that appears when you right-click an object in the Form Designer has, as its first item: 'Create default event' and selecting this option will have the same effect as selecting the ellipsis in the 物件檢視器 for the default event, usually OnClick: you are taken to the Implementation area of the 原始碼編輯器 where you can type the code for the event handler.

A common strategy in Object-Oriented programming is to provide an ActionList with the facility for entering, removing or editing a number of pre-defined actions from which the most appropriate can be selected to use in any particular instance.


Some commonly listed Actions
Action Meaning
OnChange Action to be taken if any change is detected (eg mouse move, mouse click, key press, edit text, alter picture, etc)
OnClick Action to be taken when the (first, usually left) mouse button is clicked. This is commonly the main or default action of the control; for example clicking on a button or checkbox initiates the action associated with the checkbox. It may alternatively initate a process of selection, for instance in a TextBox or Memo, or signal the beginning of painting with a Pen or Brush.
Click A method to emulate in code the effect of clicking on a control. This method is most often found in Button-type controls (TButton, TBitBtn, TSpeedButton etc). A procedure can be written that calls the same code as the OnClick action. This facility can be particularly useful if the activation of one control by clicking causes a cascade of other controls to be activated, and the Click method can be used to initiate the action rather than having the user explicitly click on a lot of controls.
OnDragDrop Action to be taken during Drag-Drop manoeuvres, ie when the mouse is used to 'capture' an item or some text etc and move it around the screen to a new location.
OnEntry Action to be taken when the mouse cursor enters the area occupied by the object, usually transfering focus to that object. This might include changes in the appearance of the object such as highlighting or raising the border.
OnExit Action to be taken when the mouse moves out of the area of the object, usually transferring focus out of the object.
OnKeyPress Action to be taken for any key-press. Subtly different from OnKeyDown, which simply responds to a key being down, whether or not it was already down when focus was given to this control. OnKeyPress requires that a key becomes pressed while focus is in this control.
OnKeyDown Action to be taken if a key is down while focus is in this control. Subtly different from OnKeyPress - for example the key might already have been down when focus entered this control, whereas OnKeyPress requires the key to become pressed while focus is in the control.
OnKeyUp Action to be taken if a key is up (ie not pressed) while focus is in this control.
OnMouseMove Action to be taken if the mouse cursor moves while focus is in this control.
OnMouseDown Action to be taken if the mouse button is down while focus is in this control.
OnMouseUp Action to be taken if the mouse button is up while the cursor is over this control. Implies that the mouse button was previously down and has been released. The case where the cursor enters the control but the mouse button has not yet been pressed is covered by OnEntry or OnMouseEnter.
OnResize Action to be taken when the control is resized. Might include re-alignment of text or selection of a different font size etc.

Contructors & Destructors

These are two special methods associated with each control:

  • Constructors: such as Create allocate memory and system resources needed by the object. They also call the constructor of any sub-objects present in the class.
  • Destructors: remove the object and de-allocate memory and other resources. If you call Destroy for an object which hasn't being initialized yet it will generate an error. Always use the Free method to deallocate objects, because it checks whether an object's value is nil before invoking Destroy.

Take the following precautions when creating your own Destroy method:

  • Declare Destroy with the override directive, because it is a virtual method.
  • Always call 'inherited Destroy;' as the last thing on the destructor code.
  • Be aware that an exception may be raised on the constructor in case there is not enought memory to create an object, or something else goes wrong. If the exception is not handled inside the constructor, the object will be only partially built. In this case Destroy will be called when you weren't expecting it, so your destructor must check if the resources were really allocated before disposing of them.
  • Remember to call Free for all objects created on the constructor.

How to use Menu Controls

Hints for creating Menus for your Forms

TMainMenu is the Main Menu that appears at the top of most forms; form designers can customise by choosing various menu items. TPopupMenu is a menu window that pops up with pertinent, usually context-sensitive, details and choices when the right mouse button is clicked near a control

Main Menu is a non-visible component : that is, if the icon is selected from the Component Palette and placed on the Form, it will not appear at Run-time. Instead, a Menu bar with a structure defined by the Menu Editor will appear. Popup menus, placed on the form by selecting the icon from the Component Palette, do not appear at all unless the right mouse button is clicked on a control that owns such a menu.

To see the Menu Editor, right-click on the Main Menu or Popup Menu icon on your Form. A pop-up box appears, that invites you to enter items into the Menu bar.

An Edit box is displayed, containing a Button labelled New Item1. If you right-click on that box, a pop-up menu is displayed that allows you to add a new item before or after (along the same level) or create a sub-menu with the opportunity to add further items below (or above) the new item in a downward column.

Any or all of the MenuItems that you add can be configured using the 物件檢視器.

At the least you should give each item a Caption which will appear on the Menu Bar (you may also wish to give it a more meaningful Name). The caption should indicate the activity to be selected, such as "File Open" or "Close", "Run" or "Quit"

If you want a particular letter in the Caption to be associated with a shortcut key, that letter should be preceded by an ampersand. The Menu item at run-time will appear with the shortcut letter underlined, and hitting that letter key will have the same effect as selecting the menu item. Alternatively you can choose a shortcut key sequence (such as Ctrl+C for Copy or Ctrl+V for Paste - the standard Keyboard shortcuts) with the ShortCut property of the MenuItem.

It is often helpful to use the Menu controls in conjuction with an ActionList which contains a series of standard or customised Actions. Menu Items can be linked in the 物件檢視器 to Actions on the list, and the same actions can be linked to Buttons, ToolBar Buttons, SpeedButtons etc. It is obviously economic of effort to re-use the same code to respond to the various events, rather than writing separate OnClick event handlers for each individual control.

By default a number of standard actions is pre-loaded from StdActns or, if DataAware controls are being used, from DBActns, and these can be chosen using the ActionList editor which appears when you right-click on the ActionList icon on the Form Designer.

除錯器

撰寫中.

可參見 IDE 視窗-除錯

The Lazarus files

   (Thanks to Kevin Whitefoot.)
   (Additions by Giuseppe Ridino, User:Kirkpatc and Tom Lisjac)

When you save you will actually be saving two files:

  xxx.pas and yyy.lpr 

(You save more than that but those are the ones you get to name). The project file (lpr) and the unit file (pas) must not have the same name because Lazarus will helpfully rename the unit (inside the source code) to the same as the unit file name and the program to the name of the project file (it needs to do this or the compiler will probably not be able to find the unit later when referred to in the project file). Of course to be consistent it changes all the occurrences of unit1 to xxx.

So if you are saving a project called again, trying to save again.pas and again.lpr fails because unit names and program names are in the same name space resulting in a duplicate name error.

So here is what I ended up with:

e:/lazarus/kj/lazhello:

total 4740  free 76500
-rwxrwxrwx   1 kjwh     root  4618697 Mar 24 11:19 again.exe
-rw-rw-rw-   1 kjwh     root     3002 Mar 24 11:21 again.lpi
-rw-rw-rw-   1 kjwh     root      190 Mar 24 11:18 again.lpr
-rw-rw-rw-   1 kjwh     root      506 Mar 24 11:08 againu.lfm
-rw-rw-rw-   1 kjwh     root      679 Mar 24 11:08 againu.lrs
-rw-rw-rw-   1 kjwh     root      677 Mar 24 11:08 againu.pas
-rw-rw-rw-   1 kjwh     root     2124 Mar 24 11:08 againu.ppu
-rwxrwxrwx   1 kjwh     root      335 Mar 24 11:07 ppas.bat

Note that there are many more files than the two that I thought I was saving.

Here is a brief note about each file:

again.exe: The main program binary executable. Win32 adds an "exe" extension. Linux has none (just the name of the program). This file will be huge in Linux due to the inclusion of debugging symbols. Run the "strip" utility to remove them and substantially shrink the executable size.

again.lpi: (Lazarus Project Information). This is the main information file of a Lazarus project; the equivalent Delphi main file of an application will be the .dpr file. It is stored in an XML format and contains instructions about all the libraries and units required to build the executable file.

again.lpr: The main program source file or master file. Despite its lazarus specific extension it is in fact a perfectly normal Pascal source file. It has a uses clause that lets the compiler find all the units it needs. Note that the program statement does not have to name the program the same as the file name. This file is usually fairly small, with just a few statements to initialise, build the forms, run and close the application. Most of the work is done in the unit source files, with suffix '.pas'

againu.lfm: This is where Lazarus stores the layout of the form unit, in human readable form. It reflects the properties of the various components, as set in the 物件檢視器. Each object description starts with a line:

object xxxx 
  then there follows a list of properties 
  (including embedded or nested objects) then an 
end 

line. Lazarus uses this file to generate a resource file (.lrs) that is included in the initialisation section of the againu.pas unit. Delphi dfm files can be converted to lfm format in the Lazarus IDE using the Tools->Convert DFM file to LFM utility.

againu.lrs: This is the generated resource file which contains the instructions to the program for building the form (if you look in the main Unit file, you will see in the initialization section the line

{$i againu.lrs} 

which instructs the program to load the resource file). Note that it is not a Windows resource file.

againu.pas: The unit that contains the code for the form; this is usually the only file that the application programmer needs to edit or inspect, and contains any code specifically supplied by the programmer (especially event handlers).

againu.ppu: This is the compiled unit which gets linked into the executable file together with any other units named in the Uses section.

ppas.bat: This is a simple script that links the program to produce the executable. If compilation is successfull, it is deleted by the compiler.

See also