Difference between revisions of "Lazarus Tutorial/zh CN"

From Lazarus wiki
Jump to navigationJump to search
Line 303: Line 303:
  
 
* '''打开包''': 显示已安装的包列表[http://lazarus-ccr.sourceforge.net/kbdata/OpenPackageSnapshot.png],[http://lazarus-ccr.sourceforge.net/kbdata/PackageContentsSnapshot.png 打开一个或更多],或选择普通或编译器选项。
 
* '''打开包''': 显示已安装的包列表[http://lazarus-ccr.sourceforge.net/kbdata/OpenPackageSnapshot.png],[http://lazarus-ccr.sourceforge.net/kbdata/PackageContentsSnapshot.png 打开一个或更多],或选择普通或编译器选项。
 +
  
 
* '''打开包文件''': 打开包文件。
 
* '''打开包文件''': 打开包文件。
 +
  
 
* '''打开最近的包''': 打开最近使用的包。
 
* '''打开最近的包''': 打开最近使用的包。
 +
  
 
* '''将活动单元添加到包''': 将单元文件添加到包中。
 
* '''将活动单元添加到包''': 将单元文件添加到包中。
 +
  
 
* '''包关系图''': 显示当前正在使用的软件包[http://lazarus-ccr.sourceforge.net/kbdata/PackageGraphSnapshot.png 关系图](如果你没有使用其他包,将显示Lazarus包和FCL及LCL包。)
 
* '''包关系图''': 显示当前正在使用的软件包[http://lazarus-ccr.sourceforge.net/kbdata/PackageGraphSnapshot.png 关系图](如果你没有使用其他包,将显示Lazarus包和FCL及LCL包。)
 +
  
 
* '''配置已安装的包''':如果你已经创建了一些组件,此项允许你配置它们。
 
* '''配置已安装的包''':如果你已经创建了一些组件,此项允许你配置它们。
 +
 
('''注意''':配图与介绍并不符合,因为Lazarus版本不同,但大多项是相似的,你可以参照着使用。)
 
('''注意''':配图与介绍并不符合,因为Lazarus版本不同,但大多项是相似的,你可以参照着使用。)
  

Revision as of 03:12, 15 January 2014

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

这是Lazarus教程的起点。你可以自由地把自己的体会添加到这里。'

概述

Lazarus是一个自由并且开源的RAD(快速应用开发)开发工具,它基于同样自由开源的FreePascal(object pascal)编译器。Lazarus IDE(screenshot)可以创建独立的(原文是self-standing,我不确认是否准确)的图形或控制台程序,同时稳定并且富于特色.目前可以运行在Linux, FreeBSD和Win32平台下,同时提供可自定义的源代码编辑器,包含包管理器的可视化GUI设计环境,以及完整地集成在GUI环境中的调试器和FreePascal编译器。

起点 - 你的第一个Lazarus程序!

(感谢User:Kirkpatc)

首先,安装(Installing Lazarus)然后运行Lazarus,当然还要确定你有可以使用的FreePascal编译器。

桌面上将出现很多窗口:顶部是主菜单,左面是对象观察器,Lazarus源代码编辑器将占据大部分的桌面,而一个预置的Form1窗体将覆盖在源代码编辑器的上面。

首先,如果你的Lazarus是全英文的,那么你可以通过主菜单上的Environment -> Environment Options打开环境设置窗口,在Desktop标签下有Language选项,改成Chinese (zh_CN),确定后重新启动下Lazarus,大部分界面就是中文的了。

注:对于linux用户,Lazarus的默认编译/安装很大可能是使用GTK1库(非常容易辩认...因为非常丑...),GTK1对于Unicode的支持不完善,无法显示中文,你可以使用GTK2重新编译Lazarus,具体方法请参照Quick start: Recompile the IDE

在顶部的主菜单上,菜单分隔线的下面有一排标签。如果Standard标签还未被选中,单击选中它。然后找到TButton图标(一个有OK字样的矩形),单击Tbutton图标,然后在Form1窗体上找个宽敞的地方单击一下。一个有着"Button1"标题的矩形按钮就出现了。重复一次,你将获得"Button2"按钮,建议你把它放到Button1的右面。

现在单击Button1选中它,左侧的对象观察器上将出现Button1对象的所有属性。找到名为Caption的属性(你可以在"收藏夹"标签下更方便地找到它),现在这个属性的值是"Button1"。单击显示着"Button1"的方格,把里面"Button1"文本改成"Press",当你按下Enter(或者单击别的方格)后,你会看见Form1窗体上的Button1按钮上的文本变成了"Press"。然后找到对象观察器上的"事件"标签,你会看见可以给Button1关联很多事件(Event),包括OnClick,OnEnter,OnExit等等。选择OnClick右边的空白方格,将出现一个显示"..."(三个点,也就是省略号)的小方格,在这个方格上单击,你将自动跳转到源代码编辑器,同时你的光标会处于一段过程(procedure)代码中:

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   {你的光标将位于这里,请输入后面的代码:}    Button1.caption := 'Press again';
   {源代码编辑器已经自动完成了这个过程的其他部分}
 end;

按下F12选中Form1窗体。

然后我们来编辑Button2的属性,将Caption修改为"Exit",然后选择OnClick事件,单击那个显示"..."的小方格,你又回到了源代码编辑器,光标位于另一段过程代码的中间:

 procedure TForm1.Button2Click(Sender: TObject);
 begin
 {输入:}   Close;
 end;

再次按下F12选中Form1窗体。现在可以尝试编译这个程序了。最简单的方法是在顶部主菜单中选择"运行",在弹出的子菜单中选择"运行"(你也可以使用快捷键F9)。如果一切顺利,你的程序将被编译执行。

所有的编辑信息都会出现在底部的"消息"窗口中。最终,一个没有刻度标记(编辑状态下才会出现)的Form1窗口将出现在屏幕上。这是你的应用程序的主窗口,它正等着你去按按钮(以及其他操作)。

尝试下点击Press按钮,你会发现按钮的标签变成了"Press again"。之后你再怎么按,它依然显示"Press again"。

现在点击Exit按钮,窗口将关闭,程序也就终止了。编辑状态下有着丑陋刻度标志的Form1又回到了屏幕上,准备接受更多的修改完善。

现在你应该保存你的工作了(你应该经常这么做!),选择顶部主菜单上的" 工程 > 保存工程 "来保存工程文件。

第二步

再次打开你保存的工程。

在Form1窗体上选择Press按钮("Button1")。

在"事件"标签中选择OnClick,点击出现的"..."方格,来回到源代码编辑器。

按照下面的文本编辑你的代码:

 procedure TForm1.Button1Click(Sender: TObject);
{这段代码使用了Button1的Tag属性,使Tag属性在0和1之间转换}
 begin
   if Button1.tag =0 then
   begin
     Button1.caption := 'Press again';
     Button1.tag := 1
   end else
   begin
     Button1.caption := 'Press';
     Button1.tag := 0
   end
 end;

保存你的工作,重新编译并且运行,Press按钮的标签将会在点击时,在两个不同的文本间来回变换了

然后,随便玩吧:]

如果你准备编写控制或者基于文本的Pascal程序(例如你正在使用一份基本的Pascal指南,准备编写在控制台环境下运行的程序,以及为系统底层编程等等),你依然可以使用Lazarus编写,编译并且运行你的程序。Lazarus是一个理想的Pascal开发环境。具体请参照Console Mode Pascal.

Lazarus编辑器

当你第一次运行Lazarus时,一系列独立的浮动窗口将出现在你的桌面上。

首先,在桌面顶部有一个窗口,标题是Lazarus 编辑器 vxxxx - project(这会随着你当前打开的工程名字而改变)。这是你工程的主要控制窗口,包括主菜单和组件面板。

Screenshot-Lazarus 编辑器 v0.9.24 测试版 - project1.png

标题栏下面是包括"文件""编辑""查找"等常见项目(以及Lazarus特有的一些项目)的主菜单。

主菜单下面,组件面板的左侧是一组按钮,包括了主菜单中的常用项目,例如新建文件,保存等等。

在这个窗口下面,左边是对象观察器

Screenshot-对象观察器.png

右边是源代码编辑器

Screenshot-Lazarus 源代码编辑器2.png

也许会有一个小窗口覆盖在源代码编辑器上,是Lazarus预置的一个Form1窗体

Screenshot-Form1.png

如果你没有看见它,可以按下F12在源代码编辑器和窗体预览间来回切换。

窗体预览展示了应用程序的图形界面,源代码编辑器则显示了应用程序所关联的Pascal代码。对象观察器则展示了组件的更多细节。

当你创建一个新工程时(或者第一次运行Lazarus时),一个默认的窗体将被创建。这个窗体包含了一个带有刻度标尺(帮助你定位放置到窗体上的组件)的区域,以及包含常见的"最小化""最大化""关闭窗口"按钮的顶部标签。用鼠标点击这个窗体,左侧的对象观察器将显示这个窗体的属性。

在你工作的时候,其他一些窗口也会出现:

包含你工程的一些细节,并且允许你从工程中添加或删除文件的工程浏览窗口

Screenshot-工程浏览 - project1.png

以及显示编译信息,错误以及运行报告的消息窗口

Screenshot-消息.png

如果你从一个终端窗口中运行Lazarus,那么这个原始的终端窗口将被保留,编译信息也会显示在这个终端窗口中。

主菜单

主菜单包括如下内容: File(文件) Edit(编辑) Search(查找) View(查看) Project(项目) Run(运行) Components(构件) Tools(工具) Environment(环境) Windows(窗口) Help(帮助)

通常情况下,你可以通过鼠标左键来点击相应的菜单功能,也可以通过热键Alt+相应热键字母(如果焦点不在菜单上,你可以使用Alt键和方向键选择菜单)

文件子菜单

Menu-file.JPG
  • 新建单元: 创建一个新的单元文件(Pascal 源代码).
  • 新建窗体: 创建一个新的窗体: 提供可视化窗口以及Pascal源代码.
  • 新建 ...: 弹出一个对话框,(screenshot) 可以选择各种类型的文档进行创建。
  • 打开: 弹出一个对话框,可以浏览文件,并选择文件打开。
  • 重新打开: 放弃你对打开文件所进行的编辑,恢复到该文件的初始状态。
  • 打开最近的文件: 列出你最近编辑的文件, 让你从中选择一个。
  • 保存: 保存当前文件, 使用其当前文件名,如果该文件未命名, 系统将提示你取一个(类似于另存为)。
  • 另存为: 允许您选择一个目录和文件名保存当前文件。
  • 全选: Lazarus翻译成“全选”,个人认为翻译成“全部保存”更好一点,顾名思义,将所有文件都保存下来。
  • 关闭: 关闭当前文件, 提示你是否保存已编辑过的文件。
  • 关闭所有编辑器中的文件: 关闭当前文件编辑器中所有的文件,提示保存已编辑的文件。
  • 清除目录: 提供可编辑的过滤器,从目录中清除项目临时文件。
  • 打印: 打印当前文件。该菜单某默认不显示,你需要安装 $Lazdir/components/printers/design/printers4lazide.pas,并重新编译IDE。
  • 重启: 退出并重新启动Lazarus。
  • 退出: 退出Lazarus,会提示你保存所有修改过的文件

编辑子菜单

EditMenu.JPG
  • 撤销: 撤销最后一次操作, 返回到上一步操作时状态。
  • 重做: 重新最后的操作,取消撤销。
  • 剪切: 删除选定的文本或其他项目,并将其放置在剪贴板中。
  • 复制: 复制选定的文本
  • 粘贴: 将剪贴板中文本复制到光标位置,如果光标位置有选定文本,剪贴板中的内容将取代所选文本。
  • 缩进所选: 将光标所选内容安装Lazarus设置缩进(环境->Options->Editor->普通->代码折叠)。这个将你的Pascle代码格式化,使之结构整齐。
  • 取消所选缩进: 删除你所选文本一个级别的缩进。
  • 封装所选: 提供一个窗口列表出一些逻辑上可以封装所选文本,如(begin ... end; try ... except; try ... finally; repeat ... until; { ... } 等等).该功能可以将所选代码包含在begin ... end;或者其他所选的块结构中.
  • 转换所选为大写: 转换选择的文本为大写.
  • 转换所选为小写: 转换选择的文本为小写.
  • 制表符转为空格: 将选择文本中的制表符转换为空格。在Environment -> Editor options -> General -> Tab widths中可以设置制表符宽度。
  • 选中节自动换行: 如果选择的内容所在行超出80个字符将不再显示,使用此功能,将会换行显示,Environment -> Editor options -> Display -> Right Margin, 设置显示宽度。
  • 注释选择: 注释选中的文本,即在行前加 // 。
  • 取消注释: 移除注释信息。
  • 排序所选: 排序所选内容,按字母顺序、区分大小写等等,在列表中对分类进行排序,它将非常有用。
  • 选择: 允许选择文本块、所有、到括号、段落、行、单词等。
  • 从字符映射表插入: 允许插入非键盘符号,如重音字符。
  • 插入文本: 弹出菜单,允许插入标准文本,如CVS关键字(作者、日期、标题等)或GPL信息,用户名或当前时间与日期。
  • 自动完成代码: 它可以节省你很多时间,在你获取或设置属性时,或使用方法时,你可以得到相关提示。在事件中加入方法,可参见Lazarus IDE工具
  • 解析过程: 使用选定文本(一条语句或多条),以创建一个新的过程。

查找子菜单

SearchMenu zh CN.png
  • 查找: 和大多编辑器一样,弹出一个搜索对话框,输入要搜索的内容,可以按大小写、全字匹配、范围、方向等查找。
  • 查找下一个, 查找上一个: 向上或向下再次搜索指定内容。
  • 在文件中查找: 在文件中搜索指定内容:在弹出的对话框中设置参数,可以按打开的文件,设定的目录,及筛选文件来查找。
  • 替换: 等同于 查找; 在弹出的替换对话框中,输入要搜索及要替换的内容。可以按区分大小写的方式,向上或向下进行替换操作。
  • 增量搜索: 高亮显示你搜索的字符串。如,选择增量搜索后,你按L后,将会高亮L显示,如果你再按A,编辑器会查找下一个LA并高亮显示。
  • 转到行: 移动光标到指定行。
  • 跳转到后一个:跳转到原来的位置。IDE会记录你的光标位置,根据它来决定你跳转或返回位置。
  • 跳转到前一个: 跳转到下一个位置。跳回来。
  • 添加跳转点到历史: 添加跳转位置到历史记录。
  • 查看跳转历史: 查看跳转点:功能未实现
  • 跳转到下一错误, 跳转到上一错误: 跳转到上一个或下一个错误处。
  • 设置一个自由书签:标记当前光标所在位置用作书签。在源文件中点击右键,在弹出来的菜单中跳到书签切换书签进行跳转操作。
  • 跳转到下一书签, 跳转到上一书签: 跳转到下一个或上一个书签。
  • 查找代码区段结束: 如果定位在beign处,则找到相应的end处,反之亦然。
  • 查找代码区段开始: 移动光标到过程或函数的begin处。
  • 在光标处查找声明: 查找选择的标识符被声明的地方,如文件没有被打开(如果是一个过程或函数的声明,如classesh.inc),将会被打开。
  • 在光标处打开文件名: 如果选择的内容是文件,将会打开它。你可以看看单元中引用的文件。
  • 前往包含指示处: 如果光标定位在包含的文件处,那么将打开包含的文件。
  • 查找标识符参考: Produces a list of all the lines in the current file, or the current project or all attached files, in which an identifier is mentioned. (显示包含标识符的过程(函数)列表。)
  • 重命名标识符: 允许开发人员重命名一个标识符。
  • 过程列表: 显示当前文件中定义的过程(函数)。

查看子菜单

ViewMenu zh CN.png

控制屏幕上的各种窗口和面板显示。

  • 对象观察器: 通常显示在编辑器的左侧,它显示了控件的属性选项。用鼠标选择列表中的控件,会显示它们的属性信息。也可以在窗体中选择控件来改变它们的属性值。

主面板中的标签“属性”:用来改变控件显示属性,如名称、颜色,标题、字体、大小等(两列中,左侧为属性,右来输入或选择属性值)。 “事件”:列表控件允许的事件,如点击、双击等。点击...在源代码编辑器中编写相应事件。 “常用”:显示常用的属性和事件列表(你也可以右击属性,也添加到“常用”中)。 “限制“,控件在各平台中的支持情况。

  • 源代码编辑器: 编辑源代码的地方。和大多图形化文本编辑器一样,可以使用鼠标定位输入位置,并支持高亮代码。右击将弹出菜单,通常包含:复制、剪切、粘贴功能。源代码编辑器顶部可多个选项卡,你可以单击来切换不同的源文件来编辑它。源代码编辑器支持缩进和语法高亮,你可以在“Environment”->"Editor"中设置相应参数。
  • 代码浏览器: 以树形方式显示定义的信息。“显示类别“:它通常只显示名称、接口部分与实现部分的定义。点击+展开显示更多。直到具体的常量、类型、变量及过程、函数的声明。如果修改了源代码,你需要点击“刷新”,来刷新文件结构。
  • 单元...:显示单元文件,显示包含的文件,并可以编辑它。允许显示多个文件,同时打开并编辑它。
  • 窗体...: 显示当前窗体列表,允许选择一个或多个。
  • 查看单元信赖关系: 以树状形式显示单元文件的信赖关系。
  • 切换窗体/单元 视图 F12: 切换源代码编辑器和窗体。你也可以按F12键来切换。
  • 消息:显示编译器消息,编译进度或编译错误的信息。
  • 查找结果: 显示找到文件的结果。
  • 调试窗口: 在子菜单中选择用于操作和配置的调试器。具体可以参看调试器

工程子菜单

ProjectMenu zh CN.png
  • 新建工程...: 在弹出的对话框中,选择工程类型,以创建一个新工程。
  • 从文件新建工程...: 打开“选择程序源代码”窗口,选择一个文件,以创建新的项目。
  • 打开工程... 打开“打开工程文件(*.lpi)”窗口,选择一个工程文件,以打开工程。
  • 打开最近的工程...: 显示最近打开的工程列表,以供选择。
  • 保存工程: 等同于“文件”->“保存”,将当前工程文件全部保存,如果工程文件未保存,将提示保存它。
  • 工程另存为...: 输入工程名后,另存工程,默认工程名为Project1.lpi;Lazarus不允许你使用相同名称做为项目文件、单元文件名。(参见 下文)。
  • 发布工程...: 创建整个项目的副本。一个正常的项目目录包含了大量信息,大部分不需要再作发布:lpi文件包含会话信息(如光标位置,单元标签等),项目目录也包含了很多ppu、o及可执行文件。此功能在对话框中你可以设置过滤器排除掉那些无用的文件;也可以使用命令压缩为一个文件。参见 Lazarus IDE 工具
  • 工程浏览器: 以树状列出当前工程包含的文件及需要的包,你可以删除,或打开选择的文件,也可以添加文件到工程。
  • 工程选项...: 配置工程,在这里,你可以设置程序标题,目标文件名等详细信息。
  • 编译器选项 ...: (Recently moved here from the Run Menu). Opens a multi-page tabbed window which allows configuration of the compiler. Tabs include Paths which allows definition of search paths for units, include files, libraries etc, as well as allowing choice of widget type for the forms (gtk, gnome, win32); Parsing which allows choice of rules for parsing source programs, Code which allows choice of optimisation for faster or smaller programs, choice of target processor, types of checks, heap size etc; Linking allowing choice of whether or how to use debugging, static or dynamic libraries, and whether to pass options through to the linker; Messages to define what type of messages should be generated during error conditions; Other which allows decision to use default configuration file (fpc.cfg) or some other file; Inherited which shows a tree structure diagram to indicate how options have been inherited from units already incorporated; Compilation which allows definition of commands to be executed before or after the compiler is launched and can allow use of Make files.
  • 添加代码编辑器中的文件到工程: 添加文件到当前项目。
  • 从工程中移除...: 在弹出的窗口中,选择文件,以从当前工程中移除。
  • View Source: 显示代码编辑器。
  • 显示 ToDo 列表:显示与此项目有关的待办事项。它将列出项目中的TODO注释(//TODO)。

新版本(如1.0.14),Ctrl+Shift+T键,在当前位置添加一个TODO。格式如// TODO : 待办说明。

运行子菜单

RunMenu zh CN.png
  • 构建: 构建(即编译)项目。
  • 构建所有: 编译项目中所有的文件。
  • 中止构建: 停止构建,一旦它运行——停止时会造成一些异常,如IDE失去响应。(你需要在任务管理器中关闭IDE进程)
  • 运行: 常用的方式编译程序,如果成功将开始运行程序;实际情况时,Lazarus保存编辑的文件,启动编译器和链接器。最后执行链接后的可执行程序。
  • 暂停: 暂停执行当前正在运行的程序,这样你可以检查调试输出。通过“运行”可进行恢复。
  • 单步进入: 与调试器配合使用,程序一步一步的执行。
  • Step over: Causes stepwise execution up to the statement marked, then skips the marked statement, and continues execution at normal speed. Useful in trying to isolate a statement that introduces a logical error.
  • 运行到光标处: 执行到光标所在位置,然后停止。通过“运行“恢复程序继续执行。
  • 停止: 停止当前正在运行的程序。无法通过“运行”恢复,这将再次启动程序。
  • 带参数运行: 打开“带参数运行”窗口,将参选参数传递给程序。你可以选择一个运行终端(如X终端);一些系统环境变量可以被覆盖。
其用途时,在Pascal控制台显示终端窗口。

如果你正在开发一个控制台模式的Pascal程序(即不使用图形界面),你应该勾选"使用运行的应用程序"。

当你尝试编译/运行程序时,会得到错误消息:

"xterm: Can't execvp /usr/share/lazarus//tools/runwait.sh: Permission denied".(大意为:权限不足。) 

如果出现这种情况,你需要设置程序的拥有可执行权限(如使用 chmod +x 文件名);程序启动后,程序的所有输入/输出都将在控制台中显示。

程序执行完毕,“Press Enter”显示在屏幕上,这时,程序之前的输入/输出都将在屏幕上显示,直至你按 Enter关闭控制台窗口。

注意: 作为当前版本,对Windows用户,没有控制台命令。直到Lazarus团队的adressess说,下面一行应该工作(on WinXP -- someone please update for other Windowses)

C:\Windows\system32\cmd.exe /C ${TargetCmdLine}

参见Pascal 控制台模式的单独教程。

  • 重置调试器: 恢复调试器到最初状态,这时候,变量、断点的值都将重置。
  • 构建文件: 编译(构建)当前文件。
  • 运行文件: 编译、链接并执行当前文件。
  • 配置 编译+运行 文件: 打开“配置构建”窗口,进行构建设置。

--Feibaicamel 14:28, 31 12月 2009 (CET)

包子菜单

PackageMenu zh CN.png


  • 打开包文件: 打开包文件。


  • 打开最近的包: 打开最近使用的包。


  • 将活动单元添加到包: 将单元文件添加到包中。


  • 包关系图: 显示当前正在使用的软件包关系图(如果你没有使用其他包,将显示Lazarus包和FCL及LCL包。)


  • 配置已安装的包:如果你已经创建了一些组件,此项允许你配置它们。

注意:配图与介绍并不符合,因为Lazarus版本不同,但大多项是相似的,你可以参照着使用。)

工具子菜单

ToolsMenu zh CN.png
  • 配置外部工具: 允许用户添加各种外部工具(通常是宏)。


  • 快速语法检查: 非实际编译任何源文件,只进行语法快速检查。在开发大的或复杂的程序时,使用此项将节省你的时间;因为编译代码时错误是不可避免的。


  • 猜测未关闭的块: 这是个有用的工具,假设你的一个复杂的嵌套块,缺少end块,使用此项功能可能会帮到你。


  • 猜测错位的IFDEF/ENDIF: 如果你有一个复杂的嵌套,缺少或错位endif时,此项功能会帮到你。


  • 生成资源字符串: Makes the selected string a resource string by placing it in the resourcestrings section. An advantage of resource strongs is you can change them without the need to recompile your project!


  • 比较Diff: 允许两个文件进行比较(通常是文件的不同版本)。允许设置一些选项进行比较。


  • 在编辑器中检查LFM文件: 检查lfm文件。




  • 构建Lazarus: 重新构建Lazarus,按下按钮,等待构建。(在消息窗口会有状态显示。)


  • 配置 ”构建Lazarus: 允许用户确定Lazarus哪部分重建,以及如何重建。如,你可以重建LCL,或一些小部分,你可以选择目标系统,并指定不同目录。

The Environment sub-menu

EnvironmentMenu.png
  • Environment options: Displays a multi-page window with tabs for
    • Files - allowing the user to specify path to default directory, compiler, source directory and temporary directory for compilation;
    • Desktop - options for Language, Auto save behaviour, saving desktop properties, hints for component palette and speed buttons;
    • Windows, to allow specification of size and behaviour of the various windows;
    • Form Editor - choose colours for editing forms;
    • Object Inspector - choose colour and height of items;
    • Backup - specify how to backup files when editing;
    • Naming - specify pascal文件使用哪种扩展名('.pp' or '.pas'), whether to save files with names in lowercase, whether to perform auto-delete or auto-rename.
  • Editor options: Multi-page window, with tabs for
    • General - determines behaviour like auto-indent, bracket highlighting, drag-drop editing, scrolling, syntax highlighting, showing hints, size of block indent and tabs, limit of Undo;
    • Display - options for showing line numbers, presence of gutters, size and type of font for editor, and contains a preview panel showing the colours of the various syntax features such as comments, directives, punctuation, errors and breakpoints;
    • Key Mappings - options to select Lazarus or Turbo Pascal scheme;
    • Color - allows choice of colour scheme for text features, for a number of language types such as Object Pascal, C++, Perl, HTML, XML and shell scripts. It shows preview panel again (for whichever language is selected);
    • Code Tools - allows selection of features like Identifier Completion, tooltips, specification of template file names, specific templates for code completion.
  • Debugger Options: Multi-page window with tabs for
    • General - choose debugger: none, GNU debugger (gdb) or gdb through SSH, specify search paths for debuggers,and specific options for chosen debugger;
    • Event log - specify whether to clear log on run, and which messages to display;
    • Language Exceptions - select which exceptions can be ignored;
    • OS Exceptions - allows user to add certain signals which apply to current operating system (not implemented).
  • Code Tool Options: Multi-page window, tabs for
    • General - Allows entry of additional source search paths, specify Jumping Method;
    • Code Creation - determines whether created code is added before or after certain features;
    • Words - determines whether Pascal keywords are to be entered in upper or lower case, or as Capitalised Words;
    • Line Splitting - establish rules about where lines are allowed to be split (before or after punctuation, after keywords etc);
    • Space - decide whether a space is to be added automatically before or after certain syntactic features such as keywords or punctuation marks.
  • Code Tools Defines Editor: Here you can see all IDE internal definitions to parse sources. You will see all the defines, unit, source, include paths for all source directories. Beginning with the settings of the current FPC, the defines for the Lazarus Source directory, all package directories and project directories.

Most of these settings are auto generated and read only.


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

The Windows sub-menu

WindowsMenu.png

Contains a list of the currently opened files and the available windows such as Source Editor, Object Inspector and Project Inspector. Clicking on the name of one of the windows brings it to the foreground and gives it focus.

帮助子菜单

At present this has three selections:

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

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

  • About Lazarus 显示一个弹出式窗口,里面有一些关于Lazarus的信息.

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

The Button bar

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

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

The Component Palette

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

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

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

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

TABS (the names are largely self-explanatory):

Component Palette Standart.png
Frequently used components: TMainMenu, TPopupMenu, TButton, TLabel, TEdit, TMemo, TToggleBox, TCheckBox, TRadioButton, TListBox, TComboBox, TScrollBar, TGroupBox, TStaticText, TRadioGroup, TCheckGroup, TPanel, TActionList
Component Palette Additional.png
More, often-used components: TBitBtn, TSpeedButton, TImage, TShape, TBevel, TPaintBox, TNotebook, TLabeledEdit, TSplitter, TMaskEdit, TCheckListBox, TScrollBox, TApplicationProperties, TStringGrid, TDrawGrid, TPairSplitter
Component Palette Common Controls.png
TTrackBar, TProgressBar, TTreeView, TListView, TStatusBar, TToolBar, TUpDown, TPageControl, TImageList
Component Palette Dialogs.png
TOpenDialog, TSaveDialog, TSelectDirectoryDialog, TColorDialog, TFontDialog, TOpenPictureDialog, TSavePictureDialog, TCalendarDialog, TCalculatorDialog

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

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

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

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

  • Misc
Component Palette Misc.png
TColorButton, TSpinEdit, TArrow, TCalendar, TEditButton, TFileNameEdit, TDirectoryEdit, TDateEdit, TCalcEdit, TFileListBox
  • Data Controls
Component Palette DataControls.png
Data-aware components, which largely replicate the Standard and Additional groups but are applicable to Databases: TDBNavigation, TDBText, TDBEdit, TDBMemo, TDBImage, TDBListBox,TDBComboBox, TDBCheckBox, TDBRadioGroup, TDBCalendar, TDBGroupBox, TdbGrid
  • Data Access
Component Palette DataAccess.png
TDatasource
Component Palette System.png
TTimer, TIdleTimer, TProcess
  • SynEdit
Component Palette SynEdit.png
A group of components to help interfacing with other languages and software tools. SynEdit is an advanced multi-line edit control, for Borland Delphi, Kylix and C++Builder. It supports Syntax Highlighting and code completion, and includes exporters for html, tex and rtf. It is a full-VCL/CLX control, meaning it is not a wrapper for Microsoft Windows controls, and no run-time library is required; this make SynEdit a crossplatform component. Compatibility with FreePascal is also planned, and SynEdit is the edit component in Lazarus IDE. see synedit at sourceforge. TSynEdit, TSynAutoComplete, TSynExporterHTML, TSynMacroRecorder, TSynMemo, TSynPasSyn, TSynCppSyn, TSynJavaSyn, TSynPerlSyn, TSynHTMLSyn, TSynXMLSyn, TSynLFMSyn, TSynUNIXShellScriptSyn, TSynCssSyn, TSynPHPSyn, TSynTeXSyn, TSynSQLSyn, TSynMultiSyn

To use the Palette, there must be an open form on view in the editor (if there isn't one, select File -> New Form). Click on the icon in the appropriate tab of the Palette for the component you want to use, then click on the Form, near where you want the component to appear. When the desired component appears, you can select it by clicking with the mouse, then move it to the exact place on the Form where you want it and adjust its size. Adjustments can be made to the appearance either by altering the picture itself on the Form using the mouse, or by changing the relevant Property in the Object Editor for that component.

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

The Debugger

Still to be written.

see also category: IDE Window - Debug

The Lazarus files

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

When you save you will actually be saving two files:

  xxx.pas and yyy.lpr 

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

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

So here is what I ended up with:

e:/lazarus/kj/lazhello:

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

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

Here is a brief note about each file:

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

again.lpi: This is the main file of a Lazarus project (Lazarus Project Information); the equivalent Delphi main file of an application will be the .dpr file. It is stored in an XML format.

again.lpr: The main program source 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.

againu.lfm: This is where Lazarus stores the layout of the form unit. Lazarus uses this to generate a resource file that is included in the initialisation section of the againu.pas unit. Delphi dfm files can be converted to lfm format in the Lazarus IDE using the Tools->Convert DFM file to LFM utility.

againu.lrs: This is the generated resource file. Note that it is not a Windows resource file.

againu.pas: The unit that contains the code for the form.

againu.ppu: This is the compiled unit.

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.

Original contributors and changes

This page has been imported from the epikwiki version.

  • Created initial page and template. T. Lisjac - 11/04/2003 VlxAdmin
  • 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
  • Per above, moved Chris's writeup to the main body of the tutorial VlxAdmin
  • Began to insert text describing the Lazarus Editor - more to follow! 24 Mar 2004 User:Kirkpatc
  • Added some more to Lazarus Editor section of Tutorial. 25 Mar 2004 User:Kirkpatc
  • Added screenshots and revised some of the page formatting VlxAdmin 3/25/2004
  • 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
  • Formatted, added credits and comments. Removed original notes. VlxAdmin 3/26/2004
  • More material added to Editor section of tutorial. 26 Mar 2004 User:Kirkpatc
  • 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
  • Inserted section on Run sub-menu. Some general editing (eg ended each entry with a period to ensure consistency). 9 Apr 2004 User:Kirkpatc
  • Inserted a new section on How to get started with MySQL in FPC/Lazarus. 13 Apr 2004 User:Kirkpatc
  • Deleted the section on MySQL from here: it has been copied to Lazarus Database section of tutorial. 14 Apr 2004 User:Kirkpatc
  • Added some more to the description of the Editor Main Menu. 18 Apr 2004 User:Kirkpatc
  • Added section on Environment sub-menu. 19 Apr 2004 User:Kirkpatc
  • Added section on Components sub-menu. 4 May 2004 User:Kirkpatc
  • Adding Tools sub-menu description (incomplete). 7 May 2004 User:Kirkpatc
  • Added some screenshots to Menu descriptions. 9 May 2004 User:Kirkpatc
  • Fixed a bit in Environment Options - thanks VincentSnijders. 14 May 2004 User:Kirkpatc
  • More additions to Tools sub-menu. 19 May 2004 User:Kirkpatc
  • Added a section on the Button Bar and started work on The Component Palette. 20 May 2004 User:Kirkpatc
  • Posted a description file for the StdCtrls unit of the LCL, in the hope that people will add comments. 26 May 2004 User:Kirkpatc
  • 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
  • Expanding on the Components Palette. 5 June 2004 User:Kirkpatc
  • Added a lot to the DialogExamples page. 10 June 2004 User:Kirkpatc
  • 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
  • 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
  • Added page for Common Controls (linked to Component Palette). 16 June 2004 User:Kirkpatc
  • Added MaskEdit page (linked to Component Palette). 17 June 2004 User:Kirkpatc
  • Added Buttons, ExtCtrls pages (linked to Component Palette). 17 June 2004 User:Kirkpatc
  • Edited MainMenu component description page. 23 June 2004 User:Kirkpatc
  • Some additions to Common Controls. 28 June 2004 User:Kirkpatc
  • A new tutorial on Text-mode Pascal programming has been added. 5 July 2004 User:Kirkpatc
  • Minor changes to ComCtrls, ExtCtrls, Environment Menu. 10 July User:Kirkpatc
  • Added FormsTxt, component description page for Component Palette. 20 July 2004 User:Kirkpatc
  • Some corrections to ConsoleModePascal. 21 July 2004 User:Kirkpatc
  • Some small changes to ComponentPalette. 22 July 2004 User:Kirkpatc
  • 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
  • Uploaded some more up-to-date screenshots and fixed links in descriptions of the Menus. 2 October 2007 User: Kirkpatc
  • Fixed links for component descriptions in Extra Controls section of Component Palette. 2 October 2007 User: Kirkpatc