Sign in Join
Wiki copytemporary

Lazarus Tutorial/zh CN: 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是一个自由并且开源的RAD(快速应用开发)开发工具,它基于同样自由开源的FreePascal(object pascal)编译器。Lazarus IDE([screenshot](http://lazarus-ccr.sourceforge.net/kbdata/lazide.jpg))可以创建独立的(原文是self-standing,我不确认是否准确)的图形或控制台程序,同时稳定并且富于特色.目前可以运行在Linux, FreeBSD和Win32平台下,同时提供可自定义的源代码编辑器,包含包管理器的可视化GUI设计环境,以及完整地集成在GUI环境中的调试器和FreePascal编译器。
66
77## 起点 - 你的第一个Lazarus程序!
88
99(感谢User:Kirkpatc)
1010
1111首先,[[Installing Lazarus/zh CN|安装Lazarus]],然后运行Lazarus,当然还要确定你有可以使用的FreePascal编译器。
1212
1313桌面上将出现很多窗口:顶部是主菜单,左面是对象观察器,Lazarus源代码编辑器将占据大部分的桌面,而一个预置的Form1窗体将覆盖在源代码编辑器的上面。
1414
1515首先,如果你的Lazarus是全英文的,那么你可以通过主菜单上的Environment -\> Environment Options打开环境设置窗口,在Desktop标签下有Language选项,改成Chinese (zh_CN),确定后重新启动下Lazarus,绝大部分界面就是中文的了。
1616
1717注:对于linux用户,Lazarus的默认编译/安装很大可能是使用GTK1库(非常容易辩认...因为非常丑...),GTK1对于Unicode的支持不完善,无法显示中文,你可以使用GTK2重新编译Lazarus,具体方法请参照[[Quick start: Recompile the IDE]]。
1818
1919在顶部的主菜单上,菜单分隔线的下面有一排标签。如果Standard标签还未被选中,单击选中它。然后找到TButton图标(一个有OK字样的矩形),单击Tbutton图标,然后在Form1窗体上找个宽敞的地方单击一下。一个有着"Button1"标题的矩形按钮就出现了。重复一次,你将获得"Button2"按钮,建议你把它放到Button1的右面。
2020
2121现在单击Button1选中它,左侧的对象观察器上将出现Button1对象的所有属性。找到名为Caption的属性(你可以在"收藏夹"标签下更方便地找到它),现在这个属性的值是"Button1"。单击显示着"Button1"的方格,把里面"Button1"文本改成"Press",当你按下Enter(或者单击别的方格)后,你会看见Form1窗体上的Button1按钮上的文本变成了"Press"。然后找到对象观察器上的"事件"标签,你会看见可以给Button1关联很多事件(Event),包括OnClick,OnEnter,OnExit等等。选择OnClick右边的空白方格,将出现一个显示"..."(三个点,也就是省略号)的小方格,在这个方格上单击,你将自动跳转到源代码编辑器,同时你的光标会处于一段过程(procedure)代码中:
2222
2323` procedure TForm1.Button1Click(Sender: TObject);`\
2424` begin`\
2525`   {你的光标将位于这里,请输入后面的代码:}`\
2626`   Button1.caption := 'Press again';`\
2727`   {源代码编辑器已经自动完成了这个过程的其他部分}`\
2828` end;`
2929
3030按下F12选中Form1窗体。
3131
3232然后我们来编辑Button2的属性,将Caption修改为"Exit",然后选择OnClick事件,单击那个显示"..."的小方格,你又回到了源代码编辑器,光标位于另一段过程代码的中间:
3333
3434` procedure TForm1.Button2Click(Sender: TObject);`\
3535` begin`\
3636`   {输入:}`\
3737`   Close;`\
3838` end;`
3939
4040再次按下F12选中Form1窗体。现在可以尝试编译这个程序了。最简单的方法是在顶部主菜单中选择"运行",在弹出的子菜单中选择"运行"(你也可以使用快捷键F9)。如果一切顺利,你的程序将被编译执行。
4141
4242所有的编译信息都会出现在底部的"消息"窗口中。最终,一个没有刻度标记(编辑状态下才会出现)的Form1窗口将出现在屏幕上。这是你的应用程序的主窗口,它正等着你去按按钮(以及其他操作)。
4343
4444尝试下点击Press按钮,你会发现按钮的标签变成了"Press again"。之后你再怎么按,它依然显示"Press again"。
4545
4646现在点击Exit按钮,窗口将关闭,程序也就终止了。编辑状态下有着丑陋刻度标志的Form1又回到了屏幕上,准备接受更多的修改完善。
4747
4848现在你应该保存你的工作了(你应该经常这么做!),选择顶部主菜单上的" 工程 \> 保存工程 "来保存工程文件。
4949
5050### 第二步
5151
5252再次打开你保存的工程。
5353
5454在Form1窗体上选择Press按钮("Button1")。
5555
5656在"事件"标签中选择OnClick,点击出现的"..."方格,来回到源代码编辑器。
5757
5858按照下面的文本编辑你的代码:
5959
6060` procedure TForm1.Button1Click(Sender: TObject);`\
6161`{这段代码使用了Button1的Tag属性,使Tag属性在0和1之间转换}`\
6262` begin`\
6363`   if Button1.tag =0 then`\
6464`   begin`\
6565`     Button1.caption := 'Press again';`\
6666`     Button1.tag := 1`\
6767`   end else`\
6868`   begin`\
6969`     Button1.caption := 'Press';`\
7070`     Button1.tag := 0`\
7171`   end`\
7272` end;`
7373
7474保存你的工作,重新编译并且运行,Press按钮的标签将会在点击时,在两个不同的文本间来回变换了
7575
7676然后,随便玩吧:\]
7777
7878如果你准备编写控制或者基于文本的Pascal程序(例如你正在使用一份基本的Pascal指南,准备编写在控制台环境下运行的程序,以及为系统底层编程等等),你依然可以使用Lazarus编写,编译并且运行你的程序。Lazarus是一个理想的Pascal开发环境。具体请参照[[Console Mode Pascal]].
7979
8080### 第三步 常用调试方法
8181
8282新人学习不少需要调试的内容
8383
8484所以需要一些直接有效的打印出调试内容.
8585
8686比如像VB 下的 Debug.print 可直接在立即窗口中打印出调试内容
8787
8888其实可以使用
8989
9090` WriteLn('XXXX ', XXX); `
9191
9292` Write('XXXXXX');   `
9393
9494但是在网上发现不少新人使用会弹出: **project project1 raised exception class 'EInOutError' with <message:file> not open**
9595
9696异常通知
9797
9898只需要在文件头部加入预编译指令
9999
100100` {$APPTYPE CONSOLE}`
101101
102102这样调试时会弹出一个类dos对话框,输出调试的内容
103103
104104### 第四步 常用技巧
105105
106106lazaurs的编辑器蛮强大的,支持代码补全,自动完成,模板编辑,多行缩进注释,选定代码后批量更改里面的单词!
107107
1081081.代码补全
109109
110110按下键盘的Ctrl+W键!输入变量后按下这个键就OK啦~
111111
1121122.自动完成
113113
114114自动完成的快捷键大多数都冲突了,解决方法是打开 工具(T)-\>选项...-\>编辑器-\>键盘映射-\>CodeTools命令-\>标识符自动完成 上右键 编辑 ,然后根据实际情况修改吧,我的是再勾选Alt,也就是说,我的热键是Ctrl+Alt+Space!不懂的看图
115115
1161163.模板编辑
117117
118118这个也蛮简单,按下键盘的Ctrl+J,然后输入class,回车!是不是很酷!
119119
1201204.多行缩进注释
121121
122122缩进的:向左 -\> Ctrl+U
123123
124124向右 -\> Ctrl+I(选中多行代码更爽)
125125
126126多行注释:Ctrl+/
127127
1281285.选定代码后批量更改里面的单词 先选中一行代码,然后点击编辑器左边显示行号左边的那支笔,看看图哦。
129129
130130这个时候你可以输入b,变量a就全部改为b,还可以按下tab跳到下一个单词。
131131
1321326.编辑器的高亮
133133
134134`<?xml version="1.0"?>`\
135135`<CONFIG>`\
136136` <EditorOptions Version="9">`\
137137`   <Display DoNotWarnForFont="Ubuntu Mono" EditorFont="Ubuntu Mono" EditorFontSize="13">`\
138138`     <MarkupCurrentWord NoKeyword="False"/>`\
139139`   </Display>`\
140140`   <KeyMapping>`\
141141`     <default Count="1">`\
142142`       <Version Value="6"/>`\
143143`       <Item1 Name="Identifier completion">`\
144144`         <KeyA Default="False" Key1="32" Shift1="5"/>`\
145145`       </Item1>`\
146146`     </default>`\
147147`   </KeyMapping>`\
148148`   <CodeTools CodeTemplateFileName="/home/lht/.lazarus/lazarus.dci" CompletionLongLineHintTypeCompletionLongLineHintType="sclpExtendRightOnly" AutoDelayInMSec="104"/>`\
149149`   <Mouse>`\
150150`     <Default Version="1"/>`\
151151`   </Mouse>`\
152152`   <Color Version="9">`\
153153`     <LangObjectPascal Version="9">`\
154154`       <ColorScheme Value="Twilight"/>`\
155155`       <SchemeTwilight>`\
156156`         <Space Background="1973790" FrameColor="5000268" FrameStyle="slsDotted" FrameEdges="sfeBottom"/>`\
157157`         <Number Foreground="7434751"/>`\
158158`         <String Foreground="7337839"/>`\
159159`         <Symbol Foreground="clYellow"/>`\
160160`         <Comment Foreground="clSkyBlue" Style="fsItalic"/>`\
161161`         <Assembler Foreground="11715098"/>`\
162162`         <Directive Foreground="22015"/>`\
163163`         <Case_label Foreground="16541892"/>`\
164164`         <IDE_Directive Foreground="1478752"/>`\
165165`         <Reserved_word Foreground="1023473"/>`\
166166`       </SchemeTwilight>`\
167167`     </LangObjectPascal>`\
168168`     <Globals Version="9">`\
169169`       <SchemeTwilight>`\
170170`         <ahaDefault Background="1973790"/>`\
171171`       </SchemeTwilight>`\
172172`     </Globals>`\
173173`     <LangPython Version="9">`\
174174`       <SchemeTwilight>`\
175175`         <Float Foreground="8345087"/>`\
176176`         <Octal Foreground="16755455"/>`\
177177`         <Number Foreground="8345087"/>`\
178178`         <String Foreground="8388522"/>`\
179179`         <Symbol Foreground="clYellow"/>`\
180180`         <Comment Foreground="clSkyBlue"/>`\
181181`         <Hexadecimal Foreground="8345087"/>`\
182182`         <SyntaxError Foreground="16755285"/>`\
183183`         <Documentation Foreground="16755370"/>`\
184184`         <Reserved_word Foreground="43775"/>`\
185185`         <Non_reserved_keyword Foreground="8366847"/>`\
186186`       </SchemeTwilight>`\
187187`     </LangPython>`\
188188`   </Color>`\
189189`   <Misc PasExtendedKeywordsMode="True"/>`\
190190`   <General>`\
191191`     <Editor TabIndent="True" TabWidth="2"/>`\
192192`   </General>`\
193193`   <DividerDraw>`\
194194`     <LangObjectPascal>`\
195195`       <TypeSect>`\
196196`         <TopColor Value="9157119"/>`\
197197`       </TypeSect>`\
198198`       <TypeGVar>`\
199199`         <TopColor Value="9157119"/>`\
200200`       </TypeGVar>`\
201201`       <TypeGStruct>`\
202202`         <TopColor Value="9157119"/>`\
203203`       </TypeGStruct>`\
204204`       <TypeProc>`\
205205`         <TopColor Value="9157119"/>`\
206206`       </TypeProc>`\
207207`       <TypeLStruct>`\
208208`         <MaxDepth Value="1"/>`\
209209`         <TopColor Value="9157119"/>`\
210210`       </TypeLStruct>`\
211211`     </LangObjectPascal>`\
212212`   </DividerDraw>`\
213213` </EditorOptions>`\
214214`</CONFIG>`
215215
216216## IDE窗口
217217
218218当你第一次运行Lazarus时,一系列独立的浮动窗口将出现在你的桌面上。
219219
220220首先,在桌面顶部有一个窗口,标题是**Lazarus vxxxx - project**。这是你工程的主要控制窗口,包括主菜单和组件面板。
221221
222-<center>
223-
224-<figure>
225-<img src="Lazarus_IDE_2.0.0-_project1.png" title="Lazarus_IDE_2.0.0-_project1.png" />
226-<figcaption>Lazarus_IDE_2.0.0-_project1.png</figcaption>
227-</figure>
228-
229-</center>
222+![](/wiki-images/c/c8/Lazarus_IDE_2.0.0-_project1.png)
230223
231224标题栏下面是包括"文件""编辑""查找"等常见项目(以及Lazarus特有的一些项目)的主菜单。
232225
233226主菜单下面,组件面板的左侧是一组按钮,包括了主菜单中的常用项目,例如新建文件,保存等等。
234227
235228在这个窗口下面,左边是**对象查看器**
236229
237-<center>
238-
239-<figure>
240-<img src="对象查看器.png" title="对象查看器.png" />
241-<figcaption>对象查看器.png</figcaption>
242-</figure>
243-
244-</center>
230+![](/wiki-images/7/7f/%E5%AF%B9%E8%B1%A1%E6%9F%A5%E7%9C%8B%E5%99%A8.png)
245231
246232右边是**源代码编辑器**
247233
248-<center>
249-
250-<figure>
251-<img src="源代码编辑器.png" title="源代码编辑器.png" />
252-<figcaption>源代码编辑器.png</figcaption>
253-</figure>
254-
255-</center>
234+![](/wiki-images/c/c5/%E6%BA%90%E4%BB%A3%E7%A0%81%E7%BC%96%E8%BE%91%E5%99%A8.png)
256235
257236也许会有一个小窗口覆盖在源代码编辑器上,是Lazarus预置的一个Form1窗体
258237
259-<center>
260-
261-<figure>
262-<img src="Form1.png" title="Form1.png" />
263-<figcaption>Form1.png</figcaption>
264-</figure>
265-
266-</center>
238+![](/wiki-images/5/56/Form1.png)
267239
268240如果你没有看见它,可以按下F12在源代码编辑器和窗体预览间来回切换。
269241
270242窗体预览展示了应用程序的图形界面,源代码编辑器则显示了应用程序所关联的Pascal代码。对象观察器则展示了组件的更多细节。
271243
272244当你创建一个新工程时(或者第一次运行Lazarus时),一个默认的窗体将被创建。这个窗体包含了一个带有刻度标尺(帮助你定位放置到窗体上的组件)的区域,以及包含常见的"最小化""最大化""关闭窗口"按钮的顶部标签。用鼠标点击这个窗体,左侧的对象观察器将显示这个窗体的属性。
273245
274246在你工作的时候,其他一些窗口也会出现:
275247
276248包含你工程的一些细节,并且允许你从工程中添加或删除文件的**工程查看器**窗口
277249
278-<center>
279-
280-<figure>
281-<img src="工程查看器.png" title="工程查看器.png" />
282-<figcaption>工程查看器.png</figcaption>
283-</figure>
284-
285-</center>
250+![](/wiki-images/b/b4/%E5%B7%A5%E7%A8%8B%E6%9F%A5%E7%9C%8B%E5%99%A8.png)
286251
287252以及显示编译信息,错误以及运行报告的**信息**窗口
288253
289-<center>
290-
291-<figure>
292-<img src="信息.png" title="信息.png" />
293-<figcaption>信息.png</figcaption>
294-</figure>
295-
296-</center>
254+![](/wiki-images/4/47/%E4%BF%A1%E6%81%AF.png)
297255
298256如果你从一个终端窗口中运行Lazarus,那么这个原始的终端窗口将被保留,编译信息也会显示在这个终端窗口中。
299257
300258## 主菜单
301259
302260主菜单内容仔细的说明在这里:[[Main menu/zh CN]]
303261
304262## IDE选项
305263
306264在Lazarus 1.0.14版中,通过"工具"-\>"选项",可以打开IDE设置窗口。 在这里你可以对环境、编译器、JCF格式设置、代码工具、代码管理器、调试器、帮助等信息配置。
307265
308-<figure>
309-<img src="IDE选项.png" title="IDE选项.png" />
310-<figcaption>IDE选项.png</figcaption>
311-</figure>
266+![](/wiki-images/a/a8/IDE%E9%80%89%E9%A1%B9.png)
312267
313268- **环境**
314269 - **文件**:最大记录工程数、文件数及设置Lazarus目录、编译器路径、FPC源代码目录、Make文件目录等等。
315270 - **桌面**:设置IDE语言、自动保存信息等等。
316271 - **窗口**:可对窗口位置、终端输出进行相应设置。
317272 - **窗体编辑器**:对颜色、风格等设置。
318273 - **对象查看器**:对颜色、速度等设置。
319274 - **备份**:工程文件备份设置,其他文件备份设置。
320275 - **命名**:对Pascal后缀、可疑文件动作、自动重命名Pascal文件为小写、单元被重命名,更新引用等等配置。
321276 - **FPDoc编辑器**:配置FPDoc。
322277 - **文件筛选**:对单元、工程、窗体、包、其他文件设置筛选器。
323278
324279- **编辑器**
325280 - **普通**:允许设置撤销/重做次数、滚动方式、缩进与制表符、光标等设置。
326281 - **显示**:设置边界和边缝及默认编辑器字体。
327282 - **键盘映射**:快捷键设置。
328283 - **鼠标**:对鼠标操作进行相应设置。
329284 - **自动化功能**:对自动补充信息进行设置。
330285 - **代码折叠**:对代码折叠相关进行配置。
331286 - **隔离区绘制**:代码块间线条设置。
332287 - **页和Windows**:暂无。
333288
334289- **JCF格式设置**
335290 - **文件格式**:暂无。
336291 - **obfuscate**:暂无。
337292 - **clarify**:暂无。
338293 - **preprocessor**:暂无。
339294
340295- **代码工具**
341296 - **普通**:方法跳转、工程附加源文件路径等设置、pascal源文件缩进设置。
342297 - **类完成**:类、方法部分插入方式及属性自动完成配置。
343298 - **创建代码**:插入过程策略、新单元添加到uses部分等配置。
344299 - **单词**:设置关键字策略、标识符规则及例外等。
345300 - **分割行**:可设置最大行宽、不拆分前面、后面行的条件。
346301 - **空格**:空格插入方式,在关键字、标识符等前或后插入空格。
347302 - **标识符自动完成**:设置标识符自动完成条件,如添加分号时。
348303
349304- **代码管理器**
350305 - **更新**:设置优先表现模式(分类、源代码),自动刷新条件及跟随光标。
351306 - **种类**:设置只在类模式中使用变量、常量、引入、定义等。
352307 - **代码观察器**:对代码观察器进行一些配置。
353308
354309- **调试器**
355310 - **普通**:可设置调试器类型和路径调试器特殊选项等。
356311 - **事件日志**:对消息窗口进行设置,如错误时显示的颜色等。
357312 - **语言异常**:设置忽略哪些异常,如 中止、代码工具错误、Fopen错误。并允许添加忽略。
358313 - **操作系统异常**:设置操作系统异常处理方式。
359314
360315- **帮助**
361316 - **帮助选项**:设置FPC HTML文件路径、默认查看器等。
362317 - **外部**:对外部程序进行配置,如Windows、PostgreSQL、Gtk2配置名称、单元文件及位置。并允许添加外部程序。
363318
364319## 按钮栏
365320
366-<div class="floatright">
367-
368-<figure>
369-<img src="按钮.png" title="按钮.png" />
370-<figcaption>按钮.png</figcaption>
371-</figure>
372-
373-</div>
321+![](/wiki-images/d/de/%E6%8C%89%E9%92%AE.png)
374322
375323在主编辑器窗口左侧小工具栏位置,(主菜单下方与左侧组件面板中),包含一组按钮:
376324
377325“新建单元”、“新建窗体”、“打开”、“保存”、“保存所有”、“新窗体”、“切换窗体/单元”、
378326
379327“查看单元”、“查看窗体”、“运行”、“暂停”、“步进”、“下一步”、“运行,直到函数返回”。
380328
381329## 组件面板
382330
383331标签式工具栏里显示常用组件图标。
384332
385333每个选项卡使用一组不同的图标显示,选项卡组最左边的第一个图片(指向箭头),称为选择工具。
386334
387335如果你将鼠标悬停在组件面板中的图标上,将会显示该组件的提示信息。T意味着,Type类型,或者是Class组件。在窗体中,使用组件时,类将会添加到类型和接口处(通常作为TForm1一部分)。实例化处,添加到VAR部分(通常作为Form1变量)。任何方法,设计时要使用窗体或组件(程序或函数),将被放置在implementation部分。如果你要找出某一特定组件的属性,可以看组件的继承,之后检查其派生的基类型的属性。例如,你要了解TMaskEdit,可以查看TcustomMaskEdit。
388336
389337**选项卡**(通过名称可以了解的其包含了哪些组件):
390338
391339- **[标准组件](http://lazarus-ccr.sourceforge.net/index.php?wiki=StdCtrls)**
392340
393-<center>
394-
395-<figure>
396-<img src="standard.png" title="standard.png" />
397-<figcaption>standard.png</figcaption>
398-</figure>
399-
400-</center>
341+![](/wiki-images/1/1b/Standard.png)
401342
402343
403344*通常使用的组件:* [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), [TStaticText](http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tstatictext.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)
404345
405346- **[更多组件](http://lazarus-ccr.sourceforge.net/index.php?wiki=ExtCtrls)**
406347
407-<center>
408-
409-<figure>
410-<img src="additional.png" title="additional.png" />
411-<figcaption>additional.png</figcaption>
412-</figure>
413-
414-</center>
348+![](/wiki-images/2/2a/Additional.png)
415349
416350
417351*更多经常使用的组件:* [TBitBtn](http://lazarus-ccr.sourceforge.net/docs/lcl/buttons/tbitbtn.html), [TSpeedButton](http://lazarus-ccr.sourceforge.net/docs/lcl/buttons/tspeedbutton.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), [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)
418352
419353- **[公共组件](http://lazarus-ccr.sourceforge.net/index.php?wiki=ComCtrls)**
420354
421-<center>
422-
423-<figure>
424-<img src="commoncontrols.png" title="commoncontrols.png" />
425-<figcaption>commoncontrols.png</figcaption>
426-</figure>
427-
428-</center>
355+![](/wiki-images/e/e5/Commoncontrols.png)
429356
430357
431358TTrackBar, TProgressBar, TTreeView, TListView, TStatusBar, TToolBar, TUpDown, TPageControl, TImageList
432359
433360- **[对话框组件](http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogsTxt)**
434361
435-<center>
436-
437-<figure>
438-<img src="dialogs.png" title="dialogs.png" />
439-<figcaption>dialogs.png</figcaption>
440-</figure>
441-
442-</center>
362+![](/wiki-images/b/bf/Dialogs.png)
443363
444364
445365TOpenDialog, TSaveDialog, TSelectDirectoryDialog, TColorDialog, TFontDialog, TOpenPictureDialog, TSavePictureDialog, TCalendarDialog, TCalculatorDialog
446366
447367有几个有用的**[对话框](http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogExamples)**,它不在组件面板中显示,但在你可在过程函数中直接调用。
448368
449369有关组件使用的例子,请参看\$LazarusPath/lazarus/examples目录。许多程序不使用IDE组件而直接使用对话框或其他组件的调色板,或者有一个单独的窗体定义文件:所有组件中,在Pascal主程序部分定义使用。
450370
451371一些示例,不马上使用的:你可能需要调整路径和文件(目录)的执行权限。如果你想直接编译示例,请确保对文件(目录)具有读取/写入/执行权限。
452372
453373请尝试运行**testall程序**,以查看可用组件和示例菜单,大多数的测试,可以确定你的环境是否能够正常使用这些组件!
454374
455375- **杂项组件**
456376
457-<center>
458-
459-<figure>
460-<img src="misc.png" title="misc.png" />
461-<figcaption>misc.png</figcaption>
462-</figure>
463-
464-</center>
377+![](/wiki-images/3/3d/Misc.png)
465378
466379
467380[TColorButton](http://lazarus-ccr.sourceforge.net/index.php?wiki=DialogsTxt), TSpinEdit, TArrow, TCalendar, TEditButton, TFileNameEdit, TDirectoryEdit, TDateEdit, TCalcEdit, TFileListBox
468381
469382- **数据组件**
470383
471-<center>
472-
473-<figure>
474-<img src="datacontrols.png" title="datacontrols.png" />
475-<figcaption>datacontrols.png</figcaption>
476-</figure>
477-
478-</center>
384+![](/wiki-images/8/8a/Datacontrols.png)
479385
480386
481387*数据组件,通常用于数据库:* TDBNavigation, TDBText, TDBEdit, TDBMemo, TDBImage, TDBListBox,TDBComboBox, TDBCheckBox, TDBRadioGroup, TDBCalendar, TDBGroupBox, TdbGrid
482388
483389- **数据访问组件**
484390
485-<center>
486-
487-<figure>
488-<img src="dataaccess.png" title="dataaccess.png" />
489-<figcaption>dataaccess.png</figcaption>
490-</figure>
491-
492-</center>
391+![](/wiki-images/9/94/Dataaccess.png)
493392
494393
495394TDatasource
496395
497396- **系统组件**
498397
499-<center>
500-
501-<figure>
502-<img src="system.png" title="system.png" />
503-<figcaption>system.png</figcaption>
504-</figure>
505-
506-</center>
398+![](/wiki-images/8/85/System.png)
507399
508400
509401[TTimer](http://lazarus-ccr.sourceforge.net/index.php?wiki=ExtCtrls#TTimer), TIdleTimer, [[doc:fcl/process/tprocess.html|TProcess]]
510402
511403- **SynEdit(~~编辑器组件~~)**
512404
513-<center>
514-
515-<figure>
516-<img src="synedit.png" title="synedit.png" />
517-<figcaption>synedit.png</figcaption>
518-</figure>
519-
520-</center>
405+![](/wiki-images/3/36/Synedit.png)
521406
522407
523408*SynEdit是一个高级的文本编辑器控制,对Borland的Delphi,Kylix、C++Builder等支持语法高亮和代码自动完成,并支持输出为HTML、Tex和RTF。这是一个VCL/CLX控件,意味着,适用于Microsoft的Windows,没有信赖的运行库,SynEdit作为跨平台组件,也是Lazarus IDE中的编辑器组件。* 查看 [sourceforge上的synedit](http://synedit.sourceforge.net). TSynEdit, TSynAutoComplete, TSynExporterHTML, TSynMacroRecorder, TSynMemo, TSynPasSyn, TSynCppSyn, TSynJavaSyn, TSynPerlSyn, TSynHTMLSyn, TSynXMLSyn, TSynLFMSyn, TSynUNIXShellScriptSyn, TSynCssSyn, TSynPHPSyn, TSynTeXSyn, TSynSQLSyn, TSynMultiSyn
524409
525410要使用调色板,必须存在窗体(如果没有,选择文件-\>新建窗体)。单击调色板中需要使用的控件,在窗体上单击,这时候,窗体上,将显示出来调色板组件;你可以调整它到合适的位置,通过属性可以显示外观。
526411
527412如果你想安装额外的组件,无论是你自己编写的,还是第三方的;完成后,将在组件面板中显示出来。
528413
529414## 如何使用通用控件
530415
531416**StdCtrls**、**ComCtrls**和**ExtCtrls**包含了常用控件的构建形式及Lazarus应用程序中常用对象。
532417
533-许多控件应用程序开发人员都要使用,如**TButton**、**TMemo**、**TScrollBar**等等。声明的控件都<b>继承</b>自父类。
418+许多控件应用程序开发人员都要使用,如**TButton**、**TMemo**、**TScrollBar**等等。声明的控件都继承自父类。
534419
535420使用这些控件时,你可以选择相应控件,在窗体上拖放就可以了。也可以使用代码创建,但是,在你不需要时,你需要销毁它。
536421
537422#### 设置属性
538423
539424在窗体设计器上放置控件后,在对象检查器中,你可以设置控件属性或编写相应事件代码。
540425
541426如,你在窗体上放置了一个按钮(TButton),选择它,并移动它以改变位置,你会可以看到它的top和left值的变化。在对象观察器中Height、Width值分别代表其大小高度和宽度。
542427
543428此外,你可以使用代码来改变对象属性:
544429
545430`Form1.Button1.Height := 48;`
546431
547432在FormCreate过程中书写上面的代码,程序运行时,将看到效果。
548433
549434总之,有三种方法,可以设置对象的属性:
550435
551436- 通过鼠标在窗体上调整
552437- 通过设置对象观察器中的值
553438- 通过代码来设置属性
554439
555440#### 公共属性
556441
557442每个组件(控件)都有不同的属性,有某些是相同的,常见的,下面这介绍这些常用属性:
558443
559-通过选择属性或关键字,在对象观察器或源代码编辑器中按<span class="kbd">F1</span>来获得帮助。
444+通过选择属性或关键字,在对象观察器或源代码编辑器中按`F1`来获得帮助。
560445
561446如果该页面上的属性描述不够,您可以通过选择继承列表中的链接或在对象声明中选择祖先类型来导航到相应的祖先类别描述。
562447
563-<table>
564-
565-<caption>
566-
567-<b>常用属性</b>
568-
569-</caption>
570-
571-<tr>
572-
573-<td>
574-
575-<b>属性</b>
576-
577-</td>
578-
579-<td>
580-
581-<b>说明</b>
582-
583-</td>
584-
585-<td>
586-
587-<b>介绍</b>
588-
589-</td>
448+常用属性
590449
591-</tr>
450+属性
592451
593-<tr>
452+说明
594453
595-<td>
454+介绍
596455
597456Action
598457
599-</td>
600-
601-<td>
602-
603458行动
604459
605-</td>
606-
607-<td>
608-
609460与对象关联的主要动作或事件。如,在选择“退出”时,会导致“关闭”。
610461
611-</td>
612-
613-</tr>
614-
615-<tr>
616-
617-<td>
618-
619462Align
620463
621-</td>
622-
623-<td>
624-
625464对齐
626465
627-</td>
628-
629-<td>
630-
631466定义与父对象对齐方式。alTop:顶对齐;alBottom:底对齐;alLeft、alRight:左对齐和右对齐;alNone:无;alClient:占用父对象所有空间。
632467
633-</td>
634-
635-</tr>
636-
637-<tr>
638-
639-<td>
640-
641468Anchor
642469
643-</td>
644-
645-<td>
646-
647470锚
648471
649-</td>
650-
651-<td>
652-
653-用于保持控件的父控件;当父控件调试大小将调整与其距离。<b>\[akBottom,akRight\]</b>将保持固定在父控制右下角距离。
654-
655-</td>
656-
657-</tr>
658-
659-<tr>
660-
661-<td>
472+用于保持控件的父控件;当父控件调试大小将调整与其距离。\[akBottom,akRight\]将保持固定在父控制右下角距离。
662473
663474AutoSelect
664475
665-</td>
666-
667-<td>
668-
669476自动选择
670477
671-</td>
672-
673-<td>
674-
675-为True时,控件在获取到焦点,或当按下<span class="kbd">Enter</span>键时选择所有文本。
676-
677-</td>
678-
679-</tr>
680-
681-<tr>
682-
683-<td>
478+为True时,控件在获取到焦点,或当按下`Enter`键时选择所有文本。
684479
685480AutoSelected
686481
687-</td>
688-
689-<td>
690-
691482自动选中
692483
693-</td>
694-
695-<td>
696-
697484True表示编辑框或组合框控件刚刚执行了“自动选择”操作,因此随后的鼠标点击和按键操作将正常进行而不会选中文本。
698485
699-</td>
700-
701-</tr>
702-
703-<tr>
704-
705-<td>
706-
707486BorderSpacing
708487
709-</td>
710-
711-<td>
712-
713488边框间距
714489
715-</td>
716-
717-<td>
718-
719490**锚定**控件与其父级之间的边缘空间。
720491
721-</td>
722-
723-</tr>
724-
725-<tr>
726-
727-<td>
728-
729492Caption
730493
731-</td>
732-
733-<td>
734-
735494标题
736495
737-</td>
738-
739-<td>
740-
741496设置显示内容,如按钮标题为“关闭”或“执行”。默认情况下,标题名称与Name属性值相同。
742497
743-</td>
744-
745-</tr>
746-
747-<tr>
748-
749-<td>
750-
751498CharCase
752499
753-</td>
754-
755-<td>
756-
757500字符显示
758501
759-</td>
760-
761-<td>
762-
763502设置字母在编辑控件中显示方式:Normal:正常(不改变字母大小写);ecLowerCase:转换为小写;ecUppercase:转换为大写。
764503
765-</td>
766-
767-</tr>
768-
769-<tr>
770-
771-<td>
772-
773504Constraints
774505
775-</td>
776-
777-<td>
778-
779506限制
780507
781-</td>
782-
783-<td>
784-
785508设置控件最大、小、高、宽度。如果调整控件大小,新的大小将在此范围内。You should take care when setting these options that they do not conflict with the Anchors and Align settings.
786509
787-</td>
788-
789-</tr>
790-
791-<tr>
792-
793-<td>
794-
795510Color
796511
797-</td>
798-
799-<td>
800-
801512颜色
802513
803-</td>
804-
805-<td>
806-
807514设置控件的文本颜色。
808515
809-</td>
810-
811-</tr>
812-
813-<tr>
814-
815-<td>
816-
817516Enabled
818517
819-</td>
820-
821-<td>
822-
823518启用
824519
825-</td>
826-
827-<td>
828-
829-设置控制是否可用,如果为False,在窗体上<b>显示为灰色</b>。
830-
831-</td>
832-
833-</tr>
834-
835-<tr>
836-
837-<td>
520+设置控制是否可用,如果为False,在窗体上显示为灰色。
838521
839522Font
840523
841-</td>
842-
843-<td>
844-
845524字体
846525
847-</td>
848-
849-<td>
850-
851526设置对象的字体信息,通常(+)号展开详细,如字体、字号、颜色等。
852527
853-</td>
854-
855-</tr>
856-
857-<tr>
858-
859-<td>
860-
861528Hint
862529
863-</td>
864-
865-<td>
866-
867530提示
868531
869-</td>
870-
871-<td>
872-
873532鼠标悬停在控件上时,弹出的提示信息。请注意ShowHint属性为True时才显示。
874533
875-</td>
876-
877-</tr>
878-
879-<tr>
880-
881-<td>
882-
883534Items
884535
885-</td>
886-
887-<td>
888-
889536项目
890537
891-</td>
892-
893-<td>
894-
895538包含的数据信息,如果文本行等。
896539
897-</td>
898-
899-</tr>
900-
901-<tr>
902-
903-<td>
904-
905540Lines
906541
907-</td>
908-
909-<td>
910-
911542列表
912543
913-</td>
914-
915-<td>
916-
917544字符串数组,包含单个数据,数组为索引从0开始,即\[0..numLines-1\]。
918545
919-</td>
920-
921-</tr>
922-
923-<tr>
924-
925-<td>
926-
927546Name
928547
929-</td>
930-
931-<td>
932-
933548名称
934549
935-</td>
936-
937-<td>
938-
939550设置控件的标识符。如TBitButton的实例,为Form1.BitBitton1、Form1.BitButton2等等,程序员应该使用见名真义的名称,如ExitButton(退出按钮)或OKButton(确定按钮)。
940551
941-</td>
942-
943-</tr>
944-
945-<tr>
946-
947-<td>
948-
949552PopUpMenu
950553
951-</td>
952-
953-<td>
954-
955554弹出式菜单
956555
957-</td>
958-
959-<td>
960-
961556设置在控件上右击时,弹出的菜单。
962557
963-</td>
964-
965-</tr>
966-
967-<tr>
968-
969-<td>
970-
971558Position (or Top, Left)
972559
973-</td>
974-
975-<td>
976-
977560位置
978561
979-</td>
980-
981-<td>
982-
983562设置控件位置。
984563
985-</td>
986-
987-</tr>
988-
989-<tr>
990-
991-<td>
992-
993564ReadOnly
994565
995-</td>
996-
997-<td>
998-
999566只读
1000567
1001-</td>
1002-
1003-<td>
1004-
1005568为True时,控件只能被读取,不能被更改。如Edit。
1006569
1007-</td>
1008-
1009-</tr>
1010-
1011-<tr>
1012-
1013-<td>
1014-
1015570ShowHint
1016571
1017-</td>
1018-
1019-<td>
1020-
1021572显示提示
1022573
1023-</td>
1024-
1025-<td>
1026-
1027574设置鼠标'悬停'在控件上时,是否显示提示信息。
1028575
1029-</td>
1030-
1031-</tr>
1032-
1033-<tr>
1034-
1035-<td>
1036-
1037576Size (or Height and Width)
1038577
1039-</td>
1040-
1041-<td>
1042-
1043578大小
1044579
1045-</td>
1046-
1047-<td>
1048-
1049580设置控件尺寸。
1050581
1051-</td>
1052-
1053-</tr>
1054-
1055-<tr>
1056-
1057-<td>
1058-
1059582Style
1060583
1061-</td>
1062-
1063-<td>
1064-
1065584样式
1066585
1067-</td>
1068-
1069-<td>
1070-
1071586样式的选项取决于所考虑的控件类型:例如,样式可以由TFormStyle、TBorderStyle、TButtonStyle等定义。
1072587
1073-</td>
1074-
1075-</tr>
1076-
1077-<tr>
1078-
1079-<td>
1080-
1081588TabOrder
1082589
1083-</td>
1084-
1085-<td>
1086-
1087590Tab键顺序
1088591
1089-</td>
1090-
1091-<td>
1092-
1093-输入整数,设置<span class="kbd">Tab</span>的顺序。
1094-
1095-</td>
1096-
1097-</tr>
1098-
1099-<tr>
1100-
1101-<td>
592+输入整数,设置`Tab`的顺序。
1102593
1103594TabStop
1104595
1105-</td>
1106-
1107-<td>
1108-
1109596制表位
1110597
1111-</td>
1112-
1113-<td>
1114-
1115-为False时,<span class="kbd">Tab</span>将无法选中此控件,否则可以。
1116-
1117-</td>
1118-
1119-</tr>
1120-
1121-<tr>
1122-
1123-<td>
598+为False时,`Tab`将无法选中此控件,否则可以。
1124599
1125600Text
1126601
1127-</td>
1128-
1129-<td>
1130-
1131602文本
1132603
1133-</td>
1134-
1135-<td>
1136-
1137604字符串文本,表示该控件包含的数据。适用于Text、Memo、StringList类型。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**.
1138605
1139-</td>
1140-
1141-</tr>
1142-
1143-<tr>
1144-
1145-<td>
1146-
1147606Visible
1148607
1149-</td>
1150-
1151-<td>
1152-
1153608可见
1154609
1155-</td>
1156-
1157-<td>
1158-
1159610为True,在窗体中可以看到此控件,否则将隐藏。
1160611
1161-</td>
1162-
1163-</tr>
1164-
1165-<tr>
1166-
1167-<td>
1168-
1169612WordWrap
1170613
1171-</td>
1172-
1173-<td>
1174-
1175614自动换行
1176615
1177-</td>
1178-
1179-<td>
1180-
1181616为True时,文本内容将自动换行。
1182617
1183-</td>
1184-
1185-</tr>
1186-
1187-</table>
1188-
1189618#### 事件动作
1190619
1191620许多行动通常列在“对象观察器”中的“事件”选项卡里。在列表中选择相应事件,在下拉列表中将会显示你已经定义的方法,并允许你对其关联。点击旁边的"..."按钮,将跳到源代码编辑器里,你在那里可以编写相应程序。
1192621
1193622“事件“选项卡中,显示了当前控件支持的事件,像OnClick事件:鼠标点击事件;OnEntry:当获得焦点时;OnExit:当失去焦点时;或者你可以编写:OnChange:内容改变时;或OnScroll:在滚动条上操作时等等,根据你的需要来选择使用哪些事件进行哪些操作。
1194623
1195624在窗体设计器上右击控件 ,“创建默认的事件“也有相同的效果,通常是OnClick(点击)事件。之后在源代码编辑器里编写相应操作。
1196625
1197626在面向对象程序设计中,使用 TActionList 组件是为了集中处理许多常用的操作,把用户界面和应用逻辑分开,减少程序的代码行数,方便程序的维护和调试。它用于维护一系列动作列表,以供其他组件或控制所使用,如菜单和按钮。
1198627
1199-\
1200-
1201-<table>
1202-
1203-<caption>
1204-
1205-<b>常用事件</b>
1206-
1207-</caption>
1208-
1209-<tr>
1210-
1211-<td>
1212-
1213-<b>事件</b>
1214-
1215-</td>
1216-
1217-<td>
1218-
1219-<b>说明</b>
1220-
1221-</td>
1222-
1223-<td>
1224-
1225-<b>介绍</b>
628+常用事件
1226629
1227-</td>
630+事件
1228631
1229-<tr>
632+说明
1230633
1231-<td>
634+介绍
1232635
1233636OnChange
1234637
1235-</td>
1236-
1237-<td>
1238-
1239638改变事件
1240639
1241-</td>
1242-
1243-<td>
1244-
1245640当检测到任何更改(如鼠标移动、点击、按键、编辑文字、更改图片等)都将触发此事件。
1246641
1247-</td>
1248-
1249-</tr>
1250-
1251-<tr>
1252-
1253-<td>
1254-
1255642OnClick
1256643
1257-</td>
1258-
1259-<td>
1260-
1261644点击事件
1262645
1263-</td>
1264-
1265-<td>
1266-
1267646鼠标点击时触发此事件(点击,指的是鼠标左键点击),点击事件大多是控件默认的事件,如点击一个按钮、单选框或复选框。
1268647
1269-</td>
1270-
1271-</tr>
1272-
1273-<tr>
1274-
1275648单击方法
1276649
1277-<td>
1278-
1279650Click
1280651
1281-</td>
1282-
1283-<td>
1284-
1285652单击方法
1286653
1287-</td>
1288-
1289-<td>
1290-
1291654单击方法,在代码中模拟点击控件。一个程序可以调用相同代码的OnClick事件,通过点击激活其他事件。这个方法可以在程序启动时使用,而不是用户点击后再进行某些操作。
1292655
1293-</td>
1294-
1295-</tr>
1296-
1297-<tr>
1298-
1299-<td>
1300-
1301656OnDragDrop
1302657
1303-</td>
1304-
1305-<td>
1306-
1307658拖放事件
1308659
1309-</td>
1310-
1311-<td>
1312-
1313660拖放操作之前,即当鼠标选中某些信息(如文本)要移动到新位置时。
1314661
1315-</td>
1316-
1317-</tr>
1318-
1319-<tr>
1320-
1321-<td>
1322-
1323662OnEditingDone
1324663
1325-</td>
1326-
1327-<td>
1328-
1329664编辑完成事件
1330665
1331-</td>
1332-
1333-<td>
1334-
1335666当用户完成编辑/修改时,通常用来验证输入内容,如检测输入的文本是不是有效的IP地址。
1336667
1337-</td>
1338-
1339-</tr>
1340-
1341-<tr>
1342-
1343-<td>
1344-
1345668OnEntry
1346669
1347-</td>
1348-
1349-<td>
1350-
1351670获得焦点事件
1352671
1353-</td>
1354-
1355-<td>
1356-
1357672当控件获取到焦点时,触发此事件。
1358673
1359-</td>
1360-
1361-</tr>
1362-
1363-<tr>
1364-
1365-<td>
1366-
1367674OnExit
1368675
1369-</td>
1370-
1371-<td>
1372-
1373676移出事件
1374677
1375-</td>
1376-
1377-<td>
1378-
1379678当鼠标移出控件区域时触发此事件。
1380679
1381-</td>
1382-
1383-</tr>
1384-
1385-<tr>
1386-
1387-<td>
1388-
1389680OnKeyPress
1390681
1391-</td>
1392-
1393-<td>
1394-
1395682按键事件
1396683
1397-</td>
1398-
1399-<td>
1400-
1401684按键事件,当按下某键时,将触发此事件。不同于OnKeyDown:当按下但不松开某键时触发此事件。
1402685
1403-</td>
1404-
1405-</tr>
1406-
1407-<tr>
1408-
1409-<td>
1410-
1411686OnKeyDown
1412687
1413-</td>
1414-
1415-<td>
1416-
1417688按下键不松事件
1418689
1419-</td>
1420-
1421-<td>
1422-
1423690如果一个键被按下,但不松开,将触发此事件。
1424691
1425-</td>
1426-
1427-</tr>
1428-
1429-<tr>
1430-
1431-<td>
1432-
1433692OnKeyUp
1434693
1435-</td>
1436-
1437-<td>
1438-
1439694松开键事件
1440695
1441-</td>
1442-
1443-<td>
1444-
1445696松开按键时触发此事件。
1446697
1447-</td>
1448-
1449-</tr>
1450-
1451-<tr>
1452-
1453-<td>
1454-
1455698OnMouseMove
1456699
1457-</td>
1458-
1459-<td>
1460-
1461700鼠标移动事件
1462701
1463-</td>
1464-
1465-<td>
1466-
1467702当鼠标在控件上移动时触发此事件。
1468703
1469-</td>
1470-
1471-</tr>
1472-
1473-<tr>
1474-
1475-<td>
1476-
1477704OnMouseDown
1478705
1479-</td>
1480-
1481-<td>
1482-
1483706鼠标按下事件
1484707
1485-</td>
1486-
1487-<td>
1488-
1489708鼠标按下但不松开时触发此事件。
1490709
1491-</td>
1492-
1493-</tr>
1494-
1495-<tr>
1496-
1497-<td>
1498-
1499710OnMouseUp
1500711
1501-</td>
1502-
1503-<td>
1504-
1505712鼠标松开事件
1506713
1507-</td>
1508-
1509-<td>
1510-
1511714鼠标按下并松开时触发此事件。
1512715
1513-</td>
1514-
1515-</tr>
1516-
1517-<tr>
1518-
1519-<td>
1520-
1521716OnResize
1522717
1523-</td>
1524-
1525-<td>
1526-
1527718改变大小事件
1528719
1529-</td>
1530-
1531-<td>
1532-
1533720调整控件大小时触发此事件。
1534721
1535-</td>
1536-
1537-</tr>
1538-
1539-</table>
1540-
1541722#### 构造和析构函数
1542723
1543724每个对象都有两个相关联的方法:
1544725
1545726- **构造函数**:在创建时,即分配对象所需内存和资源时。
1546727- **析构函数**:在删除时,即释放分配对象所需内存和资源时。
1547728
1548-释放对象,你需要使用free方法,因为它会检测对象值是否为<b>nil</b>。如果你调用已经*销毁*的对象,它将产生一个错误。
729+释放对象,你需要使用free方法,因为它会检测对象值是否为nil。如果你调用已经*销毁*的对象,它将产生一个错误。
1549730
1550731*销毁*时,注意以下:
1551732
1552-- Declare **Destroy** with the <b>override</b> directive, because it is a <b>virtual</b> method.
733+- Declare **Destroy** with the override directive, because it is a virtual method.
1553734- Always call **'inherited Destroy;**' as the last thing on the destructor code.
1554735- 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.
1555736- Remember to call **Free** for all objects created on the constructor.
1556737
1557738## 为窗体创建菜单
1558739
1559740*TMainMenu*是大多都使用的;在窗体顶部会出现菜单栏,设计者可以定制不同的菜单项。*TPopupMenu*是一个与上下文相关的菜单。通常是在控件附近点击时弹出的。
1560741
1561742主菜单是非可视组件:也就是说,在组件面板中选择菜单图标,放置在窗体上,运行时不会被显示,你需要创建菜单项,像TPopupMenu菜单,你需要关联相应组件的PopupMenu属性。
1562743
1563744若要使用菜单编辑器:右击窗体上的菜单控件,在弹出的菜单中选择*(Menu Editor)菜单编辑器*,在弹出的窗口中,对菜单进行设置。
1564745
1565746默认将显示一个NewItem1菜单项,右击它,弹出的菜单中,你可以继续在其上面或下面添加菜单,也可以子菜单。在对象观察器中,设置菜单项属性。
1566747
1567-当然,你应该给菜单项起个有意义的名字,如File open(打开文件)、Close(关闭)等。 如果你想热键,即在菜单项后显示(&N),你只需要直接输入即可。当然,你也可以给菜单项关联快捷键,对象观察器中的ShortCut和ShortCutKey2属性,分别设置第1,2快捷键;如(复制,<span class="kbd">Ctrl</span>+<span class="kbd">C</span>;粘贴,<span class="kbd">Ctrl</span>+<span class="kbd">V</span>)。
748+当然,你应该给菜单项起个有意义的名字,如File open(打开文件)、Close(关闭)等。 如果你想热键,即在菜单项后显示(&N),你只需要直接输入即可。当然,你也可以给菜单项关联快捷键,对象观察器中的ShortCut和ShortCutKey2属性,分别设置第1,2快捷键;如(复制,`Ctrl`+`C`;粘贴,`Ctrl`+`V`)。
1568749
1569750另外,如需要在菜单项间插入一条分隔线,只需要设置菜单项的Caption属性为**-**即可。
1570751
1571752你可以结合ActionList组件,对菜单各项的事件进行统一编写。
1572753
1573754By default, a number of standard actions are pre-loaded from *StdActns* or, if DataAware controls are used, from *DBActns*. These actions can be chosen using the ActionList editor which appears when you right-click on the ActionList icon on the Form Designer.
1574755
1575756## 调试器
1576757
1577758*`待写`*`。`
1578759
1579760更多 [:category: IDE Window - Debug](/wiki-category/IDE%20Window%20-%20Debug)
1580761
1581762## Lazarus 文件
1582763
1583764`   (感谢 Kevin Whitefoot.)`\
1584765`   (Giuseppe Ridinò, `User:Kirkpatc` 和 Tom Lisjac 添加)`
1585766
1586767当你保存时,实际上会保存两个文件:
1587768
1588769`  xxx.pas 和 yyy.lpr`
1589770
1590771不止这些,还有项目文件(lpr)、单元文件(pas),名称不能相同,否则Lazarus会覆盖掉原文件,在编辑器会因为无法找到指定文件而报错。
1591772
1592773所以,你需要保存为一个不重名的项目。
1593774
1594775这是我最终的文件列表:
1595776
1596777e:/lazarus/kj/lazhello:
1597778
1598779`total 4740  free 76500`\
1599780`-rwxrwxrwx   1 kjwh     root  4618697 Mar 24 11:19 again.exe`\
1600781`-rw-rw-rw-   1 kjwh     root     3002 Mar 24 11:21 again.lpi`\
1601782`-rw-rw-rw-   1 kjwh     root      190 Mar 24 11:18 again.lpr`\
1602783`-rw-rw-rw-   1 kjwh     root      506 Mar 24 11:08 againu.lfm`\
1603784`-rw-rw-rw-   1 kjwh     root      679 Mar 24 11:08 againu.lrs`\
1604785`-rw-rw-rw-   1 kjwh     root      677 Mar 24 11:08 againu.pas`\
1605786`-rw-rw-rw-   1 kjwh     root     2124 Mar 24 11:08 againu.ppu`\
1606787`-rwxrwxrwx   1 kjwh     root      335 Mar 24 11:07 ppas.bat`
1607788
1608789Note that there are many more files than the two that I thought I was saving.(~~注意,好像是多了两个文件,我想是我存的吧。~~)
1609790
1610791下面是对每个文件的简短介绍:
1611792
1612793**again.exe:** 二进制可执行文件,Win32中添加exe扩展名。linux没有。此文件在Linux上很大的原因是,加入了调试标记。 注意:在1.0.14版,可以勾选,“工程”-\>“工程选项”中的“编译选项”-\>“链接”:“从可执行程序中除去符号,可以减少程序体积(Strip Symbol)”;以减少程序体积。
1613794
1614795**again.lpi:** 它以XML格式存储,是Lazarus项目的主要文件(项目信息);Delphi应用程序文件是.dpr。
1615796
1616797**again.lpr:** 这是主程序的源代码文件,尽管使用了特定的扩展名,但它仍是正常的Pascal源文件。它有use部分,可以让编译器找到所需的单元。注意,程序名可以和该名称相同。
1617798
1618799**againu.lfm:** 存储了Lazarus窗体布局信息;也包含了初始化部分的资源文件。Delphi的DFM文件可以转换为LFM格式:“工具“-\>“转换DFM文件为LFM文件”。
1619800
1620801**againu.lrs:** 生成的资源文件。需要注意的是它不是Windows的资源文件。
1621802
1622803**againu.pas:** The unit that contains the code for the form. 包含窗体代码的单元文件。
1623804
1624805**againu.ppu:** 编译的单元文件。
1625806
1626807**ppas.bat:** 一个简单的脚本,链接程序生成可执行文件。如果编译完成,将由编译器删除。
1627808
1628809## 原作者和变化
1629810
1630811这个页面来自 ~~[这里](http://lazarus-ccr.sourceforge.net/index.php?wiki=LazarusTutorial)~~(失效)。
1631812
1632813- Created initial page and template. T. Lisjac - 11/04/2003 VlxAdmin
1633814- Inserted a note containing instructions for writing your first Lazarus Program. Suggest an administrator places it in the appropriate place on the Tutorial menu. 3/09/2004 User:Kirkpatc
1634815- Per above, moved Chris's writeup to the main body of the tutorial VlxAdmin
1635816- Began to insert text describing the Lazarus Editor - more to follow! 24 Mar 2004 User:Kirkpatc
1636817- Added some more to Lazarus Editor section of Tutorial. 25 Mar 2004 User:Kirkpatc
1637818- Added screenshots and revised some of the page formatting VlxAdmin 3/25/2004
1638819- Moved some of kwhitefoot's comments into Tutorial section. Formatting not quite right, but have to go to bed now! 26 Mar 2004 User:Kirkpatc
1639820- Formatted, added credits and comments. Removed original notes. VlxAdmin 3/26/2004
1640821- More material added to Editor section of tutorial. 26 Mar 2004 User:Kirkpatc
1641822- More material added describing the Main Menu. Renamed 'Hello World' to 'Getting Started' and moved it to nearer the top. 31 March 2004 User:Kirkpatc
1642823- Inserted section on Run sub-menu. Some general editing (eg ended each entry with a period to ensure consistency). 9 Apr 2004 User:Kirkpatc
1643824- Inserted a new section on How to get started with MySQL in FPC/Lazarus. 13 Apr 2004 User:Kirkpatc
1644825- Deleted the section on MySQL from here: it has been copied to Lazarus Database section of tutorial. 14 Apr 2004 User:Kirkpatc
1645826- Added some more to the description of the Editor Main Menu. 18 Apr 2004 User:Kirkpatc
1646827- Added section on Environment sub-menu. 19 Apr 2004 User:Kirkpatc
1647828- Added section on Components sub-menu. 4 May 2004 User:Kirkpatc
1648829- Adding Tools sub-menu description (incomplete). 7 May 2004 User:Kirkpatc
1649830- Added some screenshots to Menu descriptions. 9 May 2004 User:Kirkpatc
1650831- Fixed a bit in Environment Options - thanks VincentSnijders. 14 May 2004 User:Kirkpatc
1651832- More additions to Tools sub-menu. 19 May 2004 User:Kirkpatc
1652833- Added a section on the Button Bar and started work on The Component Palette. 20 May 2004 User:Kirkpatc
1653834- Posted a description file for the StdCtrls unit of the LCL, in the hope that people will add comments. 26 May 2004 User:Kirkpatc
1654835- Edited the StdCtrls file, removing a lot of repetitive material and doing some formatting. It is still far too long. 28 May 2004 User:Kirkpatc
1655836- Expanding on the Components Palette. 5 June 2004 User:Kirkpatc
1656837- Added a lot to the DialogExamples page. 10 June 2004 User:Kirkpatc
1657838- Considerable revision of the StdCtrls page, hopefully making it clearer and encouraging people to contribute - particularly in the 'Description' sections. 14 June 2004 User:Kirkpatc
1658839- Added pages for Menus and Dialogs units (linked to Component Palette description) - please feel free to add to these pages. 14 June 2004 User:Kirkpatc
1659840- Added page for Common Controls (linked to Component Palette). 16 June 2004 User:Kirkpatc
1660841- Added MaskEdit page (linked to Component Palette). 17 June 2004 User:Kirkpatc
1661842- Added Buttons, ExtCtrls pages (linked to Component Palette). 17 June 2004 User:Kirkpatc
1662843- Edited MainMenu component description page. 23 June 2004 User:Kirkpatc
1663844- Some additions to Common Controls. 28 June 2004 User:Kirkpatc
1664845- A new tutorial on Text-mode Pascal programming has been added. 5 July 2004 User:Kirkpatc
1665846- Minor changes to ComCtrls, ExtCtrls, Environment Menu. 10 July User:Kirkpatc
1666847- Added FormsTxt, component description page for Component Palette. 20 July 2004 User:Kirkpatc
1667848- Some corrections to ConsoleModePascal. 21 July 2004 User:Kirkpatc
1668849- Some small changes to ComponentPalette. 22 July 2004 User:Kirkpatc
1669850- Returned after a long absence! Changed link for component descriptions in StdCntls group of ComponentPalette to point directly at the Lazarus on-line help html pages. 25 Sept 2007 User: Kirkpatc
1670851- Uploaded some more up-to-date screenshots and fixed links in descriptions of the Menus. 2 October 2007 User: Kirkpatc
1671852- Fixed links for component descriptions in Extra Controls section of Component Palette. 2 October 2007 User: Kirkpatc
1672853- Uploaded some more up-to-date screenshots,and fix some more up-to-date item. 12 October 2018 User: robsean
1673854- Uploaded some more up-to-date screenshots,and fix some more up-to-date item. 15 February 2019 User: robsean
1674855
1675856---
1676857*From the Free Pascal wiki, page "Lazarus Tutorial/zh CN", as it stood on 2023-03-31 after a change by Owenlmg, 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).*
1677858Category: zh

Back to history