Sign in Join
Wiki copytemporary

Lazarus Tutorial/zh TW: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*這是篇 Lazarus 教學的起頭,各位可自由地改進他。*
22
33## 概述
44
55Lazarus 是一個使用 Pascal 編譯器的自由開放原始碼開發工具。Free Pascal 本身也是自由開放軟體。Lazarus IDE ([擷圖](http://lazarus-ccr.sourceforge.net/kbdata/lazide.jpg)) 提供一穩定,且專注於強調豐富的程式寫作環境,並用來開發單機的圖形與主控台應用程式。Lazarus 目前可以在 Linux,Mac OS X 與 Win32 下執行。且提供可自訂的原始碼編輯器,並透過套件管理,除錯器與完整的圖形使用介面整合的編譯器做成視覺化的表格創建環境。
66
77## 我們開始吧
88
99(感謝 User:Kirkpatc)
1010
1111取得並安裝 ([[Installing Lazarus]]) Lazarus,同時安裝所有所需的 Free Pascal 編譯器後執行 Lazarus。
1212
1313註:在 Linux Ubuntu 下,在主控台啟動 Lazarus 的指令是 "startlazarus"。如果你是從 Debian 的套件來安裝,你應該會在開始選單裡的應用程式/程式寫作 (Application/Programming) 下找到程式捷徑來啟動。 (己知問題: 在 Debian 或 Ubuntu 裡的主要執行檔與套件已經改名成 "lazarus-ide",因為已經有個 "tct" 的工具套件被取名叫 "lazarus"。)
1414
1515### 你的第一個 Lazarus 程式!
1616
1717從主選單裡,選擇〔專案〕 - 〔新增專案-應用程式〕 (Project - New Project-Application)。 幾個視窗會出現在你的桌面上:上方的主選單,左方的物件檢視器,Lazarus 原始碼編輯器佔桌面的一大半部份,並有一個已經備妥的 Form1 視窗於原始碼編輯器重疊著出現。 在上方的選單視窗,選單列的下方,有一排標籤頁。如果 '標準 (Standard)' 籤頁沒有被選取,請用滑鼠點選他。然後找到〔按鈕〕 (Button) 的圖示 (一個裡面寫著 'OK' 的四方形) 後用滑鼠按一下,游標再移到 Form1 的視窗,大概移到中間偏左的地點再按一下滑鼠鍵。一個立體的四方形,標著 'Button1' 的按鈕物件就會出現。再按一次標準籤頁裡的鈕按圖示,然後移到 Form1 中間偏右的地方再按一次,就會出現一個標著 'Button2' 的按鈕出現。
1818
1919現在點一下 Button1 來選取它。物件檢視器會顯示出該 Button1 物件的所有內容,靠上的有一項名為 '標題 (Caption)' 的內容,裡面顯示的值是 'Button1'。點一下那個方格,將 'Button1' 改成 '按我'。如果你再按一下 ENTER 或點一下其它的方格,你就會見到原來第一個按鈕裡面標的字就會變成 '按我'。現在點選物作視察器裡的〔事件〕 (Events) 籤頁,裡面會列出所有與這個按鈕有關的事件項目。像是 OnClick,OnEnter,OnExit 等等。再選取 OnClick 右邊的方格,方格會出現三個小點的省略符號。當你再按取該省略符號,會你自動被帶進入原始碼編輯裡,且游標被定在你該撰寫讓事件原始碼的開始處:
2020
2121` procedure TForm1.Button1Click(Sender: TObject);`\
2222` begin`\
2323`   {現在輸入:}    Button1.caption := '再按一次';`\
2424`   {程序於此完結}`\
2525` end;`
2626
27-按一下 <span class="kbd">F12</span> 從原始碼編輯器回到 Form1 的視窗。
27+按一下 `F12` 從原始碼編輯器回到 Form1 的視窗。
2828
2929現在接著編輯 Button2 的〔內容〕:按一下 Button2 使物件檢視器裡顯示出它的內容,變更他的〔標題〕成 '離開'。然後接著再選 OnClick 事件,再點省略符號,這時你又回到原始碼編輯器,從另一段程序開始寫作:
3030
3131` procedure TForm1.Button2Click(Sender: TObject);`\
3232` begin`\
3333`   {現在輸入:}   Close;`\
3434`   {程序於此完結}`\
3535` end;`
3636
37-現在再按 <span class="kbd">F12</span> 來看看你的 Form1 視窗。現在該是儲存你的工作的時候了 (而且應該時常)!點選專案 \> 另存專案 \> 你取的檔名.pas (Project \> Save Project As \> your_selected_file_name.pas)。然後程式會再要求你儲存你的專案資訊,副案名為 .lpi。選一個不同的檔名,如果兩個取了同樣的檔名,你在編譯的時候會遇上 "重覆的識別子" 的錯誤 (請見此教學最後一章節 "Lazarus 檔案")。 你現在已經準備好可以開始編譯了。最簡單的方法就是在上方的主選單裡選 '執行 (Run)' 子選單,然後再按 '執行'。或是最直接地按 F9。程式會進行第一次的編譯並直接執行你的程式。
37+現在再按 `F12` 來看看你的 Form1 視窗。現在該是儲存你的工作的時候了 (而且應該時常)!點選專案 \> 另存專案 \> 你取的檔名.pas (Project \> Save Project As \> your_selected_file_name.pas)。然後程式會再要求你儲存你的專案資訊,副案名為 .lpi。選一個不同的檔名,如果兩個取了同樣的檔名,你在編譯的時候會遇上 "重覆的識別子" 的錯誤 (請見此教學最後一章節 "Lazarus 檔案")。 你現在已經準備好可以開始編譯了。最簡單的方法就是在上方的主選單裡選 '執行 (Run)' 子選單,然後再按 '執行'。或是最直接地按 F9。程式會進行第一次的編譯並直接執行你的程式。
3838
3939有幾個文字視窗會在你編譯的時候出現,顯示著你編譯時的所出現的訊息。但直到最後你的 Form1 視窗會重新出現,而且不帶有格子和標點。這就是你的應用程式的主畫面,並正等待你去按按鈕來與它互動。
4040
4141試著去點標著 '按我' 的按鈕。你會注意到它變成了 '再按一次',但如果你再按一次,他還是一樣顯示 '再按一次'!
4242
4343現在在按標著 '離開' 的按鈕,視窗會關閉,程式也隨之結束。然後又回到那個有格子與標點的 Form1 視窗,等待你再進一步的修改它。
4444
4545### 改進你的程式
4646
4747再一次開啟你剛儲存的專案。 在 Form1 視窗下點選 '按我' 按鈕 (Button1)。 再選物件檢視器裡的〔事件〕籤頁,點選方格右邊的省略符號,回到原始碼編輯器的相對地方。
4848
4949如下編輯你的程式碼:
5050
5151` procedure TForm1.Button1Click(Sender: TObject);`\
5252`{使用一個標記物,設定它是1或是零}`\
5353` begin`\
5454`   if Button1.tag = 0 then`\
5555`   begin`\
5656`     Button1.caption := '再按一次';`\
5757`     Button1.tag := 1`\
5858`   end else`\
5959`   begin`\
6060`     Button1.caption := '按我';`\
6161`     Button1.tag := 0`\
6262`   end`\
6363` end;`
6464
6565儲存你的工作,再重新編譯一次並執行。現在你左邊的按鈕就會交替地顯示訊息了。
6666
6767接下來就完全看你自己了!
6868
6969如果你偏好撰寫主控台下的 Pascal 程式 (比如說你正在上一堂 Pascal 的課要交作業用,或是為一個系統撰寫巨集指令),你也仍然可以使用 Lazarus 來撰寫、編譯並執行。有關於這個部份的開發,請見 [[Console Mode Pascal|主控台模式的 Pascal]] 的章節。
7070
7171## 視窗編輯器
7272
7373當你第一次執行起 Lazarus,會出現一系列不連續的,或說浮動著的視窗。
7474
7575首先,桌面最上方會的標題會是 **Lazarus 編輯 vXXXXXX - 專案1** (會隨著你目前的專案名稱變化)。這是控制你專案的主視窗,包含了主選單與元件面板。
7676
77-<center>
78-
79-<figure>
80-<img src="LazMain_GTK2.png" title="LazMain_GTK2.png" />
81-<figcaption>LazMain_GTK2.png</figcaption>
82-</figure>
83-
84-</center>
77+![](/wiki-images/4/43/LazMain_GTK2.png)
8578
8679標題列下面的橫幅就是*主選單 (Main Menu)*,有著一般常見的檔案,編輯,搜尋與檢視分類項目,下面還有幾個區塊來執行 Lazarus 的特定工作。 再下來的橫幅左邊是一些符號 (可以迅速執行你要的指令);而右邊就是元件面板。
8780
88-在 Lazarus 編輯器視窗下左邊顯示的是**[物件檢視器](http://lazarus-ccr.sourceforge.net/kbdata/objinsp.jpg)**視窗,而**[Lazarus 原始碼編輯器](http://lazarus-ccr.sourceforge.net/kbdata/editor.jpg)**在右邊。那裡還有很多其他的小視窗,標著 **[Form1](http://lazarus-ccr.sourceforge.net/kbdata/blankform.jpg)**,並與 Lazarus 原始碼編輯器的視窗重疊著。如果無法立即找到他,可以按下 <span class="kbd">F12</span> 在原始碼編輯器與表單之間切換顯示。表單視窗就是指你用來為你的應用程式建立圖形介面的地方,並直接與你撰寫中的 Pascal 原始碼關聯上。而物件檢視器的操作會在解說元件面板的時候一起做更多說明。最後,我們還有一個訊息視窗在螢幕的最下方,這裡 Lazarus 會顯示要告訴程式設計師訊息,例如你在編譯過程出了問題。
81+在 Lazarus 編輯器視窗下左邊顯示的是**[物件檢視器](http://lazarus-ccr.sourceforge.net/kbdata/objinsp.jpg)**視窗,而**[Lazarus 原始碼編輯器](http://lazarus-ccr.sourceforge.net/kbdata/editor.jpg)**在右邊。那裡還有很多其他的小視窗,標著 **[Form1](http://lazarus-ccr.sourceforge.net/kbdata/blankform.jpg)**,並與 Lazarus 原始碼編輯器的視窗重疊著。如果無法立即找到他,可以按下 `F12` 在原始碼編輯器與表單之間切換顯示。表單視窗就是指你用來為你的應用程式建立圖形介面的地方,並直接與你撰寫中的 Pascal 原始碼關聯上。而物件檢視器的操作會在解說元件面板的時候一起做更多說明。最後,我們還有一個訊息視窗在螢幕的最下方,這裡 Lazarus 會顯示要告訴程式設計師訊息,例如你在編譯過程出了問題。
8982
9083當你要新開一個新的專案 (或是當你第一次開啟 Lazarus),一份預設的的表單視窗會先建立好,上面會帶有許多格點用來幫助你定位在上面各似各樣的元件。而最上面一條細長的橫幅就是常見的**縮到最小**,**放到最大**與**關閉**視窗按鈕。點擊表單框框裡隨便一個物作,桌面左側的物件檢視器就會顯示出此物件的所有內容。
9184
9285你在工作的過程中還有可能會看到一些其他的視窗:像**[專案檢視器](http://lazarus-ccr.sourceforge.net/kbdata/projinsp.jpg)**,含有你的專案裡所擁有的檔案的詳細資料,讓你可對專案新加入或是刪除檔案。**訊息**視窗,用來顯示你的專案在編譯過程中出現的錯誤或任何訊息。如果你是在遠端執行 Lazarus,則你原來的這一端還是可以看到在編譯時出現的訊息。
9386
9487## 主選單
9588
9689主選單内容仔細的説明在這裡:[[Main menu/zh TW]]
9790
9891## The Button bar
9992
10093A 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:
10194
10295在主編輯視窗左方一個小的工具欄區域,就在主選單下方以及套件板的左邊,包含了一組按鈕用來呼叫一些常用的主選單功能:
10396
10497
10598**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).
10699
107100## The Component Palette
108101
109102A Tabbed toolbar which displays a large number of icons representing commonly used components for building Forms.
110103
111104Each 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.
112105
113106If 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|type]]** section of the **[[Interface|interface]]** part of the [[Unit]] (usually as part of the overall TForm1), and an **instance** of that class is added to the **[[Var|var]]** section (usually as the variable Form1). Any **Methods** that you design to be used by the Form or its Components (ie [[Procedure|Procedures]] or [[Function|Functions]]) will be placed in the **[[Implementation|implementation]]** part of the Unit.
114107
115108#### How To Use the Palette
116109
117110To 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.
118111
119112Adjustments 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.
120113
121114If 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.
122115
123116In 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.
124117
125118#### [Standard](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/index-4.html)
126119
127120(See [[Standard tab]] for components description)
128121
129-<center>
130-
131-<figure>
132-<img src="Component_Palette_Standart.png" title="Component_Palette_Standart.png" />
133-<figcaption>Component_Palette_Standart.png</figcaption>
134-</figure>
135-
136-</center>
122+![](/wiki-images/4/4d/Component_Palette_Standart.png)
137123
138124
139125*Frequently used components:* [TMainMenu](http://lazarus-ccr.sourceforge.net/docs/lcl/menus/tmainmenu.html), [TPopupMenu](http://lazarus-ccr.sourceforge.net/docs/lcl/menus/tpopupmenu.html), [TButton](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tbutton.html), [TLabel](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tlabel.html), [TEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tedit.html), [TMemo](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tmemo.html), [TToggleBox](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/ttogglebox.html), [TCheckBox](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tcheckbox.html), [TRadioButton](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tradiobutton.html), [TListBox](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tlistbox.html), [TComboBox](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tcombobox.html), [TScrollBar](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tscrollbar.html), [TGroupBox](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tgroupbox.html), [TRadioGroup](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tradiogroup.html), [TCheckGroup](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tcheckgroup.html), [TPanel](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tpanel.html), [TActionList](http://lazarus-ccr.sourceforge.net/docs/lcl/actnlist/tactionlist.html)
140126
141127#### [Additional](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/index-4.html)
142128
143129(See [[Additional tab]] for components description)
144130
145-<center>
146-
147-<figure>
148-<img src="Component_Palette_Additional.png" title="Component_Palette_Additional.png" />
149-<figcaption>Component_Palette_Additional.png</figcaption>
150-</figure>
151-
152-</center>
131+![](/wiki-images/7/7d/Component_Palette_Additional.png)
153132
154133
155134*More, often-used components:* [TBitBtn](http://lazarus-ccr.sourceforge.net/docs/lcl/buttons/tbitbtn.html), [TSpeedButton](http://lazarus-ccr.sourceforge.net/docs/lcl/buttons/tspeedbutton.html), [TStaticText](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tstatictext.html), [TImage](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/timage.html), [TShape](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tshape.html), [TBevel](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tbevel.html), [TPaintBox](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tpaintbox.html), [TNotebook](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tnotebook.html), [TLabeledEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tlabelededit.html), [TSplitter](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tsplitter.html), [TTrayIcon](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/ttrayicon.html), [TMaskEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/maskedit/tmaskedit.html), [TCheckListBox](http://lazarus-ccr.sourceforge.net/docs/lcl/checklst/tchecklistbox.html), [TScrollBox](http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tscrollbox.html), [TApplicationProperties](http://lazarus-ccr.sourceforge.net/docs/lcl/forms/tapplicationproperties.html), [TStringGrid](http://lazarus-ccr.sourceforge.net/docs/lcl/grids/tstringgrid.html), [TDrawGrid](http://lazarus-ccr.sourceforge.net/docs/lcl/grids/tdrawgrid.html), [TPairSplitter](http://lazarus-ccr.sourceforge.net/docs/lcl/pairsplitter/tpairsplitter.html), [TColorBox](http://lazarus-ccr.sourceforge.net/docs/lcl/colorbox/tcolorbox.html), [TColorListBox](http://lazarus-ccr.sourceforge.net/docs/lcl/colorbox/tcolorlistbox.html), [TChart](http://lazarus-ccr.sourceforge.net/docs/lcl/chart/index.html)
156135
157136#### [Common Controls](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/index-4.html)
158137
159138(See [[Common Controls tab]] for components description)
160139
161-<center>
162-
163-<figure>
164-<img src="Component_Palette_Common_Controls.png" title="Component_Palette_Common_Controls.png" />
165-<figcaption>Component_Palette_Common_Controls.png</figcaption>
166-</figure>
167-
168-</center>
140+![](/wiki-images/4/4a/Component_Palette_Common_Controls.png)
169141
170142
171143[TTrackBar](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttrackbar.html), [TProgressBar](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tprogressbar.html), [TTreeView](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttreeview.html), [TListView](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tlistview.html), [TStatusBar](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tstatusbar.html), [TToolBar](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttoolbar.html), [TUpDown](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tupdown.html), [TPageControl](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tpagecontrol.html), [TTabControl](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/ttabcontrol.html), [THeaderControl](http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/theadercontrol.html), [TImageList](http://lazarus-ccr.sourceforge.net/docs/lcl/controls/timagelist.html), [TPopupNotifier](http://lazarus-ccr.sourceforge.net/docs/lcl/popupnotifier/index.html)
172144
173145#### [Dialogs](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/index-4.html)
174146
175147(See [[Dialogs tab]] for components description)
176148
177-<center>
178-
179-<figure>
180-<img src="Component_Palette_Dialogs.png" title="Component_Palette_Dialogs.png" />
181-<figcaption>Component_Palette_Dialogs.png</figcaption>
182-</figure>
183-
184-</center>
149+![](/wiki-images/7/72/Component_Palette_Dialogs.png)
185150
186151
187152[TOpenDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/topendialog.html), [TSaveDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tsavedialog.html), [TSelectDirectoryDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tselectdirectorydialog.html), [TColorDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tcolordialog.html), [TFontDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tfontdialog.html), [TFindDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tfinddialog.html), [TReplaceDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/treplacedialog.html), [TOpenPictureDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/extdlgs/topenpicturedialog.html), [TSavePictureDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/extdlgs/tsavepicturedialog.html), [TCalendarDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/extdlgs/tcalendardialog.html), [TCalculatorDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/extdlgs/tcalculatordialog.html), [TPrinterSetupDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tcustomprintersetupdialog.html), [TPrintDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tcustomprintdialog.html), [TPageSetupDialog](http://lazarus-ccr.sourceforge.net/docs/lcl/dialogs/tcustomprintersetupdialog.html)
188153
189154Several useful **[Dialog](http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples)** procedures or functions don't appear on the Palette, but are easily used as direct calls from your source program.
190155
191156For 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.
192157
193158Remember 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.
194159
195160Some 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.
196161
197162Try 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!
198163
199164#### [[Misc]]
200165
201-<center>
202-
203-<figure>
204-<img src="Component_Palette_Misc.png" title="Component_Palette_Misc.png" />
205-<figcaption>Component_Palette_Misc.png</figcaption>
206-</figure>
207-
208-</center>
166+![](/wiki-images/8/8e/Component_Palette_Misc.png)
209167
210168
211169[TColorButton](http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogsTxt), [TSpinEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/spin/tspinedit.html), [TFloatSpinEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/spin/tfloatspinedit.html), [TArrow](http://lazarus-ccr.sourceforge.net/docs/lcl/arrow/tarrow.html), [TCalendar](http://lazarus-ccr.sourceforge.net/docs/lcl/calendar/tcalendar.html), [TEditButton](http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/teditbutton.html), [TFileNameEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/tfilenameedit.html), [TDirectoryEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/tdirectoryedit.html), [TDateEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/tdateedit.html), [TCalcEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/editbtn/tcalcedit.html), [TFileListBox](http://lazarus-ccr.sourceforge.net/docs/lcl/filectrl/tfilelistbox.html), [TXMLPropStorage](http://lazarus-ccr.sourceforge.net/docs/lcl/xmlpropstorage/txmlpropstorage.html), [TIniPropStorage](http://lazarus-ccr.sourceforge.net/docs/lcl/inipropstorage/tinipropstorage.html), [TBarChart](http://lazarus-ccr.sourceforge.net/docs/lcl/chart/tbarchart.html), [TButtonPanel](http://lazarus-ccr.sourceforge.net/docs/lcl/buttonpanel/tbuttonpanel.html), TIDEDialogLayoutStorage
212170
213171#### [Data Controls](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/index-4.html)
214172
215-<center>
216-
217-<figure>
218-<img src="Component_Palette_DataControls.png" title="Component_Palette_DataControls.png" />
219-<figcaption>Component_Palette_DataControls.png</figcaption>
220-</figure>
221-
222-</center>
173+![](/wiki-images/6/62/Component_Palette_DataControls.png)
223174
224175
225176*Data-aware components, which largely replicate the Standard and Additional groups but are applicable to Databases:* [TDBNavigator](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbnavigator.html), [TDBText](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbtext.html), [TDBEdit](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbedit.html), [TDBMemo](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbmemo.html), [TDBImage](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbimage.html), [TDBListBox](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdblistbox.html), [TDBComboBox](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbcombobox.html), [TDBCheckBox](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbcheckbox.html), [TDBRadioGroup](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbradiogroup.html), [TDBCalendar](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbcalendar.html), [TDBGroupBox](http://lazarus-ccr.sourceforge.net/docs/lcl/dbctrls/tdbgroupbox.html), [TDBGrid](http://lazarus-ccr.sourceforge.net/docs/lcl/dbgrids/tdbgrid.html)
226177
227178#### [[Data Access]]
228179
229-<center>
230-
231-<figure>
232-<img src="Component_Palette_DataAccess.png" title="Component_Palette_DataAccess.png" />
233-<figcaption>Component_Palette_DataAccess.png</figcaption>
234-</figure>
235-
236-</center>
180+![](/wiki-images/c/cc/Component_Palette_DataAccess.png)
237181
238182
239183TDatasource, TMemDataset, TSdfDataSet, TFixedFormatDataSet, TDbf
240184
241185#### [[System]]
242186
243-<center>
244-
245-<figure>
246-<img src="Component_Palette_System.png" title="Component_Palette_System.png" />
247-<figcaption>Component_Palette_System.png</figcaption>
248-</figure>
249-
250-</center>
187+![](/wiki-images/f/fe/Component_Palette_System.png)
251188
252189
253190[TTimer](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/ttimer.html), [TIdleTimer](http://lazarus-ccr.sourceforge.net/docs/lcl/extctrls/tidletimer.html), [TLazComponentQueue](http://lazarus-ccr.sourceforge.net/docs/lcl/lresources/tlazcomponentqueue.html), [THtmlHelpDatabase](http://lazarus-ccr.sourceforge.net/docs/lcl/lazhelphtml/thtmlhelpdatabase.html), [THtmlBrowserHelpViewer](http://lazarus-ccr.sourceforge.net/docs/lcl/lazhelphtml/thtmlbrowserhelpviewer.html), [TProcessUTF8](http://lazarus-ccr.sourceforge.net/docs/lcl/asyncprocess/tprocessutf8.html), [TAsyncProcess](http://lazarus-ccr.sourceforge.net/docs/lcl/asyncprocess/tasyncprocess.html), [[doc:fcl/process/tprocess.html|TProcess]], TSimpleIPCClient, TSimpleIPCServer, TXMLConfig, TEventLog
254191
255192#### [[SynEdit]]
256193
257-<center>
258-
259-<figure>
260-<img src="Component_Palette_SynEdit.png" title="Component_Palette_SynEdit.png" />
261-<figcaption>Component_Palette_SynEdit.png</figcaption>
262-</figure>
263-
264-</center>
194+![](/wiki-images/2/22/Component_Palette_SynEdit.png)
265195
266196
267197''SynEdit is an advanced multi-line edit control, which is integrated into the Lazarus.
268198
269199''SynEdit 是一個整合至 Lazarus 的進階的多行編輯控制。
270200
271201
272202''It is the code editor of the Lazarus IDE and is available in the directory "lazarus/components/synedit".
273203
274204''它是 Lazarus IDE 的源碼編輯器,可以在 "lazarus/components/synedit" 目錄中取得。
275205
276206
277207''It supports Syntax Highlighting, code completion, code folding and includes exporters for html, tex and rtf.
278208
279209''它支援語法高亮,自動完成,源碼摺疊並包含 html, tex, rtf 的輸出者。
280210
281211
282212''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.
283213
284214''它是完全使用者繪製的套件,意即它包裝了每個平台的原生控制項並且不需要任何外部的 library; 這讓 SynEdit 成為一個跨平台的套件。
285215
286216
287217''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](http://synedit.sourceforge.net). : TSynEdit, TSynAutoComplete, TSynExporterHTML, TSynMacroRecorder, TSynMemo, TSynPasSyn, TSynFreePascalSyn, TSynCppSyn, TSynJavaSyn, TSynPerlSyn, TSynHTMLSyn, TSynXMLSyn, TSynLFMSyn, TSynUNIXShellScriptSyn, TSynCssSyn, TSynPHPSyn, TSynTeXSyn, TSynSQLSyn, TSynPythonSyn, TSynVBSyn, TSynAnySyn, TSynMultiSyn
288218
289219## How to use Common Controls
290220
291221The 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.
292222
293-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 <b>inherited</b> by the final target control.
223+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.
294224
295225If 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.
296226
297227#### Ways to Set Properties
298228
299229If you place a component on the Form Designer and look at the 物件檢視器, you can observe the properties change as you move the component around.
300230
301231For 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.
302232
303233On 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.
304234
305235You can also explicitly change the properties of the object in code by typing (in the appropriate Implementation section of the 原始碼編輯器), for example
306236
307237`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 物件檢視器.
308238
309239In summary, there are usually about three different ways to determine each property of an object:
310240
311241- by using the mouse on the form,
312242- by setting the values in the 物件檢視器,
313243- or explicitly by writing code in the editor.
314244
315245#### Common Properties
316246
317247The 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.
318248
319-Additional Help can always be obtained by selecting a property or keyword, in either the 物件檢視器 or the 原始碼編輯器, and pressing <span class="kbd">F1</span>. You will be taken by your Help browser to the appropriate page in the documentation.
249+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.
320250
321251If 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.
322252
323-<table>
324-
325-<caption>
326-
327-<b>Some commonly listed properties</b>
328-
329-</caption>
330-
331-<tr>
332-
333-<td>
334-
335-<b>Property</b>
336-
337-</td>
338-
339-<td>
340-
341-<b>Meaning</b>
342-
343-</td>
344-
345-</tr>
253+Some commonly listed properties
346254
347-<tr>
255+Property
348256
349-<td>
257+Meaning
350258
351259Action
352260
353-</td>
354-
355-<td>
356-
357261The main action or event associated with the object. For example selecting an 'Exit' Button might cause the 'Close' action
358262
359-</td>
360-
361-</tr>
362-
363-<tr>
364-
365-<td>
366-
367263Align
368264
369-</td>
370-
371-<td>
372-
373265Defines 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)
374266
375-</td>
376-
377-</tr>
378-
379-<tr>
380-
381-<td>
382-
383267Anchor
384268
385-</td>
386-
387-<td>
388-
389-Used to keep a control a certain distance from the defined edges of a parent control, when the parent is resized. For example <b>\[akBottom, akRight\]</b> will keep the control a fixed distance from the bottom right corner.
390-
391-</td>
392-
393-</tr>
394-
395-<tr>
396-
397-<td>
269+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.
398270
399271AutoSelect
400272
401-</td>
402-
403-<td>
404-
405273When True, an editing control will select all its text when it receives focus or when the Enter key is pressed.
406274
407-</td>
408-
409-</tr>
410-
411-<tr>
412-
413-<td>
414-
415275AutoSelected
416276
417-</td>
418-
419-<td>
420-
421277True 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.
422278
423-</td>
424-
425-</tr>
426-
427-<tr>
428-
429-<td>
430-
431279BorderSpacing
432280
433-</td>
434-
435-<td>
436-
437281The space around the edge between an **Anchored** control and its parent.
438282
439-</td>
440-
441-</tr>
442-
443-<tr>
444-
445-<td>
446-
447283Caption
448284
449-</td>
450-
451-<td>
452-
453285The 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.
454286
455-</td>
456-
457-</tr>
458-
459-<tr>
460-
461-<td>
462-
463287CharCase
464288
465-</td>
466-
467-<td>
468-
469289Indicates 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
470290
471-</td>
472-
473-</tr>
474-
475-<tr>
476-
477-<td>
478-
479291Constraints
480292
481-</td>
482-
483-<td>
484-
485293Sets 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.
486294
487-</td>
488-
489-</tr>
490-
491-<tr>
492-
493-<td>
494-
495295Color
496296
497-</td>
498-
499-<td>
500-
501297The Colour to be used to draw the control or to write the text it contains.
502298
503-</td>
504-
505-</tr>
506-
507-<tr>
508-
509-<td>
510-
511299Enabled
512300
513-</td>
514-
515-<td>
516-
517-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 <b>Grayed</b> out on the Form.
518-
519-</td>
520-
521-</tr>
522-
523-<tr>
524-
525-<td>
301+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.
526302
527303Font
528304
529-</td>
530-
531-<td>
532-
533305The 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.
534306
535-</td>
536-
537-</tr>
538-
539-<tr>
540-
541-<td>
542-
543307Hint
544308
545-</td>
546-
547-<td>
548-
549309A short piece of informative pop-up text that appears if the mouse-cursor hovers over the control.
550310
551-</td>
552-
553-</tr>
554-
555-<tr>
556-
557-<td>
558-
559311Items
560312
561-</td>
562-
563-<td>
564-
565313The 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
566314
567-</td>
568-
569-</tr>
570-
571-<tr>
572-
573-<td>
574-
575315Lines
576316
577-</td>
578-
579-<td>
580-
581317An 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\]
582318
583-</td>
584-
585-</tr>
586-
587-<tr>
588-
589-<td>
590-
591319Name
592320
593-</td>
594-
595-<td>
596-
597321The 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.
598322
599-</td>
600-
601-</tr>
602-
603-<tr>
604-
605-<td>
606-
607323PopUpMenu
608324
609-</td>
610-
611-<td>
612-
613325A window containing context-sensitive menu information that pops up when the right mouse button is clicked on the object.
614326
615-</td>
616-
617-</tr>
618-
619-<tr>
620-
621-<td>
622-
623327Position (or Top, Left)
624328
625-</td>
626-
627-<td>
628-
629329Determines where the control is located on the parent form or window
630330
631-</td>
632-
633-</tr>
634-
635-<tr>
636-
637-<td>
638-
639331ReadOnly
640332
641-</td>
642-
643-<td>
644-
645333Boolean 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.
646334
647-</td>
648-
649-</tr>
650-
651-<tr>
652-
653-<td>
654-
655335ShowHint
656336
657-</td>
658-
659-<td>
660-
661337Allows a small window containing a context-sensitive Help or other description to be displayed when the mouse cursor 'hovers' over the control.
662338
663-</td>
664-
665-</tr>
666-
667-<tr>
668-
669-<td>
670-
671339Size (or Height and Width)
672340
673-</td>
674-
675-<td>
676-
677341The dimensions of the control
678342
679-</td>
680-
681-</tr>
682-
683-<tr>
684-
685-<td>
686-
687343Style
688344
689-</td>
690-
691-<td>
692-
693345The options available for Style depend upon the sort of Control being considered: for instance the Style may be defined by TFormStyle, TBorderStyle, TButtonStyle etc.
694346
695-</td>
696-
697-</tr>
698-
699-<tr>
700-
701-<td>
702-
703347TabOrder
704348
705-</td>
706-
707-<td>
708-
709349Integer defining where in the sequence of tabs on the Form this control is to lie
710350
711-</td>
712-
713-</tr>
714-
715-<tr>
716-
717-<td>
718-
719351TabStop
720352
721-</td>
722-
723-<td>
724-
725353Boolean property which if True places this control in the sequence of objects that the user can reach by successively pressing the Tab key
726354
727-</td>
728-
729-</tr>
730-
731-<tr>
732-
733-<td>
734-
735355Text
736356
737-</td>
738-
739-<td>
740-
741357The 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**.
742358
743-</td>
744-
745-</tr>
746-
747-<tr>
748-
749-<td>
750-
751359Visible
752360
753-</td>
754-
755-<td>
756-
757361If true, the object can be seen on the Form; if False, object is hidden
758362
759-</td>
760-
761-</tr>
762-
763-<tr>
764-
765-<td>
766-
767363WordWrap
768364
769-</td>
770-
771-<td>
772-
773365Logical 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.
774366
775-</td>
776-
777-</tr>
778-
779-</table>
780-
781367#### Event Actions
782368
783369Many 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.
784370
785371While 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.
786372
787373The 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.
788374
789375A 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.
790376
791-\
792-
793-<table>
794-
795-<caption>
796-
797-<b>Some commonly listed Actions</b>
798-
799-</caption>
800-
801-<tr>
802-
803-<td>
804-
805-<b>Action</b>
806-
807-</td>
808-
809-<td>
810-
811-<b>Meaning</b>
812-
813-</td>
377+Some commonly listed Actions
814378
815-<tr>
379+Action
816380
817-<td>
381+Meaning
818382
819383OnChange
820384
821-</td>
822-
823-<td>
824-
825385Action to be taken if any change is detected (eg mouse move, mouse click, key press, edit text, alter picture, etc)
826386
827-</td>
828-
829-</tr>
830-
831-<tr>
832-
833-<td>
834-
835387OnClick
836388
837-</td>
838-
839-<td>
840-
841389Action 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.
842390
843-</td>
844-
845-</tr>
846-
847-<tr>
848-
849-<td>
850-
851391Click
852392
853-</td>
854-
855-<td>
856-
857393A 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.
858394
859-</td>
860-
861-</tr>
862-
863-<tr>
864-
865-<td>
866-
867395OnDragDrop
868396
869-</td>
870-
871-<td>
872-
873397Action 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.
874398
875-</td>
876-
877-</tr>
878-
879-<tr>
880-
881-<td>
882-
883399OnEntry
884400
885-</td>
886-
887-<td>
888-
889401Action 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.
890402
891-</td>
892-
893-</tr>
894-
895-<tr>
896-
897-<td>
898-
899403OnExit
900404
901-</td>
902-
903-<td>
904-
905405Action to be taken when the mouse moves out of the area of the object, usually transferring focus out of the object.
906406
907-</td>
908-
909-</tr>
910-
911-<tr>
912-
913-<td>
914-
915407OnKeyPress
916408
917-</td>
918-
919-<td>
920-
921409Action 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.
922410
923-</td>
924-
925-</tr>
926-
927-<tr>
928-
929-<td>
930-
931411OnKeyDown
932412
933-</td>
934-
935-<td>
936-
937413Action 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.
938414
939-</td>
940-
941-</tr>
942-
943-<tr>
944-
945-<td>
946-
947415OnKeyUp
948416
949-</td>
950-
951-<td>
952-
953417Action to be taken if a key is up (ie not pressed) while focus is in this control.
954418
955-</td>
956-
957-</tr>
958-
959-<tr>
960-
961-<td>
962-
963419OnMouseMove
964420
965-</td>
966-
967-<td>
968-
969421Action to be taken if the mouse cursor moves while focus is in this control.
970422
971-</td>
972-
973-</tr>
974-
975-<tr>
976-
977-<td>
978-
979423OnMouseDown
980424
981-</td>
982-
983-<td>
984-
985425Action to be taken if the mouse button is down while focus is in this control.
986426
987-</td>
988-
989-</tr>
990-
991-<tr>
992-
993-<td>
994-
995427OnMouseUp
996428
997-</td>
998-
999-<td>
1000-
1001429Action 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.
1002430
1003-</td>
1004-
1005-</tr>
1006-
1007-<tr>
1008-
1009-<td>
1010-
1011431OnResize
1012432
1013-</td>
1014-
1015-<td>
1016-
1017433Action to be taken when the control is resized. Might include re-alignment of text or selection of a different font size etc.
1018434
1019-</td>
1020-
1021-</tr>
1022-
1023-</table>
1024-
1025435#### Contructors & Destructors
1026436
1027437These are two special methods associated with each control:
1028438
1029439- **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.
1030440
1031-- **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 <b>nil</b> before invoking **Destroy**.
441+- **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**.
1032442
1033443Take the following precautions when creating your own **Destroy** method:
1034444
1035-- Declare **Destroy** with the <b>override</b> directive, because it is a <b>virtual</b> method.
445+- Declare **Destroy** with the override directive, because it is a virtual method.
1036446- Always call **'inherited Destroy;**' as the last thing on the destructor code.
1037447- 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.
1038448- Remember to call **Free** for all objects created on the constructor.
1039449
1040450## How to use Menu Controls
1041451
1042452Hints for creating Menus for your Forms
1043453
1044454*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
1045455
1046456Main 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.
1047457
1048458To 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.
1049459
1050460An 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.
1051461
1052462Any or all of the *MenuItems* that you add can be configured using the 物件檢視器.
1053463
1054464At 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"
1055465
1056-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 <span class="kbd">Ctrl</span>+<span class="kbd">C</span> for Copy or <span class="kbd">Ctrl</span>+<span class="kbd">V</span> for Paste - the standard Keyboard shortcuts) with the *ShortCut* property of the MenuItem.
466+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.
1057467
1058468It 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.
1059469
1060470By 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.
1061471
1062472## 除錯器
1063473
1064474
1065475*撰寫中*.
1066476
1067477可參見 [IDE 視窗-除錯](/wiki-category/IDE%20Window%20-%20Debug)
1068478
1069479## The Lazarus files
1070480
1071481`   (Thanks to Kevin Whitefoot.)`\
1072482`   (Additions by Giuseppe Ridino, `User:Kirkpatc` and Tom Lisjac)`
1073483
1074484When you save you will actually be saving two files:
1075485
1076486`  xxx.pas and yyy.lpr `
1077487
1078488(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.
1079489
1080490So 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.
1081491
1082492So here is what I ended up with:
1083493
1084494e:/lazarus/kj/lazhello:
1085495
1086496`total 4740  free 76500`\
1087497`-rwxrwxrwx   1 kjwh     root  4618697 Mar 24 11:19 again.exe`\
1088498`-rw-rw-rw-   1 kjwh     root     3002 Mar 24 11:21 again.lpi`\
1089499`-rw-rw-rw-   1 kjwh     root      190 Mar 24 11:18 again.lpr`\
1090500`-rw-rw-rw-   1 kjwh     root      506 Mar 24 11:08 againu.lfm`\
1091501`-rw-rw-rw-   1 kjwh     root      679 Mar 24 11:08 againu.lrs`\
1092502`-rw-rw-rw-   1 kjwh     root      677 Mar 24 11:08 againu.pas`\
1093503`-rw-rw-rw-   1 kjwh     root     2124 Mar 24 11:08 againu.ppu`\
1094504`-rwxrwxrwx   1 kjwh     root      335 Mar 24 11:07 ppas.bat`
1095505
1096506Note that there are many more files than the two that I thought I was saving.
1097507
1098508Here is a brief note about each file:
1099509
1100510**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.
1101511
1102512**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.
1103513
1104514**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'
1105515
1106516**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:
1107517
1108518`object xxxx `\
1109519`  then there follows a list of properties `\
1110520`  (including embedded or nested objects) then an `\
1111521`end `
1112522
1113523line. 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.
1114524
1115525**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
1116526
1117527`{$i againu.lrs} `
1118528
1119529which instructs the program to load the resource file). Note that it is not a Windows resource file.
1120530
1121531**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).
1122532
1123533**againu.ppu:** This is the compiled unit which gets linked into the executable file together with any other units named in the Uses section.
1124534
1125535**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.
1126536
1127537## See also
1128538
1129539- [[Lazarus IDE Tools]]
1130540
1131541---
1132542*From the Free Pascal wiki, page "Lazarus Tutorial/zh TW", as it stood on 2022-09-29 after a change by Felizkuo, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
1133543Category: Tutorials/zh TW

Back to history