free pascal
One of the advantages of Lazarus is that you can write once and compile anywhere. Well, I want to create a CGI program with Lazarus and to do that I need something called FreeSpider, a Lazarus package for creating CGI programs (those are the programs that are running on your Internet server, most likely under Linux).
To be able to download FreeSpider, I needed the latest version of Lazarus, which is 0.9.28.3 to work with the latest stable version of Free Pascal, which is 2.4.0. Going to download Lazarus from SourceForge, gave me the proper version of Lazarus but coupled with the previous valid version of Free Pascal, namely 2.2.4. I tried to install one version of Lazarus and connect it with the standalone version of Free Pascal, but that did not work.
I dug deeper, and found a place from which you can download the latest snapshot of both Lazarus 0.9.28 and FPC 2.4.0. I installed it and yes, it worked perfectly, the very first time I tried it. Here is the code of that simplest of all simple Lazarus programs:
—————————-
program prvodugmepoc;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, nulaprvodugme, LResources
{ you can add units after this };
{$IFDEF WINDOWS}{$R prvodugmepoc.rc}{$ENDIF}
begin
{$I prvodugmepoc.lrs}
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit nulaprvodugme;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := ‘Prvo dugme’;
end;
initialization
{$I nulaprvodugme.lrs}
end.
—————————-
This code has one button and one changeable text field; clicking on the button changes the text in the text field — and it works!
Interestingly enough, this same code should be working on Lazarus under Ubuntu, of which I do have a dual boot. So Lazarus with Free Pascal is not only a Windows Pascal, it is also an “international” pascal, meaning it will feel right at home with totally disparate hosts such as Windows and/or Ubuntu.
I have found an awesome series of Free Pascal tutorials using Lazarus, on YouTube. The series starts with the basics, what a free pascal actually is. Here it is:
[youtube nqph8VGCi40]
Lazarus is an IDE for Free Pascal, that is, it is a working environment. Once you get hold on Lazarus on one platform, you can use it on other platforms just as well. The motto of Lazarus is Write Once, Compile Anywhere! and it actually holds on to that promise!