安装和使用delphi最后的余辉:lazarus集成编译环境@FreeBSD

遥想当年,最牛最流行的两个编程IDE是Delphi和Visual Basic,结果这么多年下来,VB已经没有往昔的热度,而Delphi也已经消亡在历史的长河中。不过Delphi的精神没消失,lazarus坚守delphi的编程风格,散发delphi最后的余辉。

Lazarus介绍

Lazarus是一个基于Free Pascal的跨平台集成开发环境(IDE),主要用于快速应用程序开发(RAD)。

  • Lazarus被设计为Delphi的开源替代品,它利用Free Pascal编译器,支持多种处理器架构和操作系统。
  • Lazarus的设计目标是应用Free Pascal,因此所有Free Pascal能运行的平台,Lazarus也可以运行。

Lazarus官网:Lazarus Homepage

安装Lazarus

在FreeBSD下可以直接使用pkg安装 lazarus:

pkg install lazarus-gtk2

提示:

The process will require 2 GiB more space.
229 MiB to be downloaded.
说实话,比我想像中大一点,不过我喜欢

安装完成后,提示:

Message from lazarus-gtk2-3.2.0_1:

--
The Lazarus RAD was installed

1) You can run it using:

   # lazarus

2) The first time that lazarus is running, you should set the path to fpc
   source directory at lazarus configuration environment. Also it could be
   setting later.

3) Now you can obtain freepascal source installing lang/fpc-source port or
   package

   It will be extracted to /usr/local/share/fpc-source-X.X.X

4) You can use /usr/local/bin/gdb debugger instead of gdb installed debugger
   installed from base system. Lazarus works better with this version.

5) We can use the following ports for aplications that depend of lazarus
   and these can be built with an interface different than lazarus has compiled
   by default:

   editors/lazarus
   editors/lazarus-devel
   editors/lazarus-qt5
   editors/lazarus-qt5-devel
   editors/lazarus-qt6
   editors/lazarus-qt6-devel

   You can added those ports if you want support for gtk2, qt5 or qt6
   interfaces. Please look at net-p2p/transmission-remote-gui like a example of
   how use it

6) If you want built apps using devel version of lazarus, you must add the
   following into /etc/make.conf file

   WANT_LAZARUS_DEVEL=  yes

   It is neccesary for use devel version of lazarus (gtk2, qt5 or qt6)

   editors/lazarus-devel
   editors/lazarus-qt5-devel
   editors/lazarus-qt6-devel

7) Enjoy it ;)
pkg: Package database is busy while closing!

注意它提示了fpc的位置,比如在这里:/usr/local/share/fpc-source-3.2.2

后面启动lazarus之后需要配置。 

启动lazarus

在启动界面里有小报错,说需要设置rpc路径

前面提示里写了路径,也可以手动找到rpc路径,

在启动界面里设置fpc源代码位置的目录:/usr/local/share/fpc-source-3.2.2/

调试器设置如果报错,也需要重新设置了一下:/usr/local/bin/gdb 

终于能进入编辑界面了,多少年没有看见这个delphi的界面了啊!

试了一下,果然制作gui界面还是那么简单方便啊。不过我对pascal不太熟,所以只是怀旧看一下。 

最新好消息,竟然有python插件

在“软件包”-“在线软件包”里,搜索python,可以搜到python for lazarus ,安装

不过没有使用成功,就不费劲去整了。

这里有说明,大家可以看一下:Using Python in Lazarus on Windows/Linux - Free Pascal wiki

Lazarus实践

这个项目就是Lazarus的,可以实践一下:https://github.com/dajingshan/miniframe

对Visual Basic用户专门的学习资料:Pascal for Visual Basic users - Free Pascal wiki 

运行项目

创建了一个项目,在form上放置一个按钮和一个Label,然后在点击按钮处写代码:

procedure TForm1.Button1Click(Sender: TObject);
begin
  //Label1.Caption:= "hello world ";
  Caption:='My first Form';  //Caption of Form1 is changed (text in formhead)
  //or
  Button1.Caption:='Hello';  //Caption of button is changed (shown text of button)
  Label1.Caption:='hello';
end;                     

 运行后,点击按钮,form的名字和按钮、Label上的字都变了,运行成功!

跟python比起来,感觉Free pascal 语法有如下几个注意的地方:

代码块需要用begin 开头,end; 结尾。 赋值需要用:= ,另外就是字符串需要用单引号,而不像python还可以使用双引号(这里若有错误请告知)。具体语法可以到Free Pascal官网看一下:Free Pascal - Advanced open source Pascal compiler for Pascal and Object Pascal - Home Page

总结:

Lazarus果然很棒! 让人又重温了当年激情燃烧的岁月感。

不过现在主流还是WEB+人工智能,估计Lazarus也只是Delphi最后的余辉罢了。

调试

启动lazarus的时候有小报错

目录:/usr/local/share/lazarus-3.2.0/

错误:未找到目录 rtl 您可以从 http://sourceforge.net/projects/lazarus/?source=directory 下载 FPC 和 FPC 的源代码

FreeBSD下有FPC的包,所以安装起来很简单,先search一下

pkg search fpc
pkg: No SRV record found for the repo 'FreeBSD'
fpc-3.2.2_10                   Free Pascal compiler with Turbo and Delphi compatibility
fpc-devel-3.3.1.20240503       Free Pascal compiler with Turbo and Delphi (devel)
fpc-devel-source-3.3.1.20240503 Free Pascal compiler with Turbo and Delphi compatibility (source)
fpc-docs-3.2.2                 Free Pascal compiler Adobe Acrobat(tm) documentation
fpc-source-3.2.2_5             Free Pascal compiler with Turbo and Delphi compatibility (source)
pdfpc-4.6.0_6                  Keynote-like multi-monitor presentation viewer
然后pkg 安装

pkg install fpc-3.2.2_10 fpc-source-3.2.2_5

但是说这两个已经安装好了。

终于找到了位置:/usr/local/share/fpc-source-3.2.2/ 

设置好即可。

  • 26
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值