New language additions in Free Pascal
These are many new improvements of Object Pascal programming language in Free Pascal compiler. I don’t know how much new are they, but at least they are new since Delphi 7 language. I haven’t used any of these features before (until now) because I wasn’t know about them.
1. For .. in loop:
This can be used to loop in string characters:
procedure ForInLoop(aStr: string);
var
ch: Char;
begin
for ch in aStr do
WriteLn(ch);
end;
or through set items:
procedure ForInSetLoop;
var
s: set of 1 .. 100;
i: Integer;
begin
s:= [1, 3, 7];
for i in s do
Writeln(i);
end;
2. += operator
This new operator can be used to concatenate strings and add values to numbers:
var aName: string; begin aName:= 'Free'; aName += ' Pascal'; Writeln(aName); // Free Pascal end;
For numbers:
x:= 10; x+= 15; Writeln(x); // 25
3. Properties without OOP
Now you can define a property in a structured code:
var x: Integer; procedure SetX(aX: Integer); begin x:= ax; end; function GetX: Integer; begin Result:= x; end; property MyX: Integer read GetX write SetX; // Main program begin MyX:= 170; Writeln(MyX); end.
4. Bit packed record
You can define a record of bits, and display it as byte:
type
tbit = 0..1;
tBitsByte = bitpacked record
bit0 : tbit;
bit1 : tbit;
bit2 : tbit;
bit3 : tbit;
bit4 : tbit;
bit5 : tbit;
bit6 : tbit;
bit7 : tbit;
end;
var
aByte: tBitsByte;
begin
aByte.bit0:= 1;
aByte.bit1:= 0;
aByte.bit2:= 1;
Writeln(Byte(aByte)); // 5
5. Sealed class
You can prevent inheriting from a class by adding the keyword sealed:
TMyClass = class sealed
private
fValue: Integer;
public
constructor Create(aValue: Integer);
destructor destroy; override;
function GetValue: Integer;
end;
I couldn’t find a good example right now to explain why we need to do this, but in the future I may get one.
6. Class methods and variables
You can declare methods and variables that can be used by class name before object instantiation the same like Java static methods as in this example:
TMyClass = class sealed
private
class var fValue: Integer;
public
constructor Create(aValue: Integer);
class function GetValue: Integer;
class procedure SetValue(aValue: Integer);
end;
constructor TMyClass.Create(aValue: Integer);
begin
inherited Create;
fValue:= aValue;
end;
class function TMyClass.GetValue: Integer;
begin
Result:= fValue;
end;
class procedure TMyClass.SetValue(aValue: Integer);
begin
fValue:= aValue;
end;
// Main code
begin
TMyClass.SetValue(900);
Writeln(TMyClass.GetValue);
end.
7. case of String
case aName of
'Free Pascal': Writeln('Lazarus IDE');
'C++': Writeln('CodeBlocks IDE');
end;
If you know any new useful additions please let me now to write it here.
References:
http://lazarus.freepascal.org/index.php/topic,19107.0.html
http://www.freepascal.org/docs-html/ref/refse24.html#x56-630004.6
Freepascal Answers blog 2012 in review
FreePascal answers blog review for 2012
Here’s an excerpt:
4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 13,000 views in 2012. If each view were a film, this blog would power 3 Film Festivals
Brook: a new web framework for FreePascal/Lazarus
A new and promising web development framework has been born for Free Pascal/ Lazarus developers. It supports REST, JSON, and you can download it from here:
TurboBird, a FireBird database administration tool that is written using FreePascal/Lazarus
TurboBird is a free and open source FireBird database administration tool that is written using FreePascal/Lazarus
Download page (Available for Linux, Windows, and Mac)
Development Source code in GitHub
Ohloh summary report about TurboBird

Can not load default Firebird clients (“libfbembed.so” or “libgds.so”). Check your installation
If you are using Free Pascal / Lazarus to develop applications that needs to access FireBird database, or you need to run applications that has been written using FreePascal/Lazarus and Firebird database, make sure you have installed Firebird client library.
If you have installed FireBird database engine (server) in the same machine, that means you already have this library installed, but for thee client machines you need to do the followings:
In windows you can install the client library from the same server packages that you can get from this link:
http://www.firebirdsql.org/en/server-packages/
This time choose Minimal client only installation.
In Linux you can install libfbclient2 package. For instance in Debian family you can execute this command:
sudo apt-get install libfbclient2
After installing Firebird client package you will get libraries like this in default Linux library directory:
/usr/lib/i386-linux-gnu/libfbclient.so.2 /usr/lib/i386-linux-gnu/libfbclient.so.2.5.1
Lazarus applications are still can not access them. You need to make a symbolic link by the default name to make FreePascal/Lazarus applications be able to load Firebird library.
In older versions of Linux you can do it like this:
sudo ln /usr/lib/libfbclient.so.2 /usr/lib/libfbclient.so
In newer versions of Linux use one of these two commands:
For 32 bit Linux:
sudo ln /usr/lib/i386-linux-gnu/libfbclient.so.2 /usr/lib/i386-linux-gnu/libfbclient.so
For 64 bit Linux:
sudo ln /usr/lib/x86_64-linux-gnu/libfbclient.so.2 /usr/lib/x86_64-linux-gnu/libfbclient.so
Also you can check Firebird library existence from your FreePascal/Lazarus code by doing the followings:
1. Add dynlibs in main project source code
2. Write this code before creating forms at main project code:
{$IFDEF Unix}
{$DEFINE extdecl:=cdecl}
fbclib = 'libfbclient.' + sharedsuffix;
{$ENDIF}
{$IFDEF Windows}
{$DEFINE extdecl:=stdcall}
fbclib = 'fbclient.dll';
seclib = 'gds32.dll';
{$ENDIF}
{$R *.res}
var
IBaseLibraryHandle : TLibHandle;
begin
IBaseLibraryHandle:= LoadLibrary(fbclib);
{$IFDEF Windows}
if IBaseLibraryHandle = NilHandle then
IBaseLibraryHandle:= LoadLibrary(seclib);
{$ENDIF}
// Check Firebird library existance
if (IBaseLibraryHandle = nilhandle) then
Application.MessageBox('Unable to load Firebird library: ' + #10 + fbclib,
'Warning', 0);
Application.Initialize;
Application.CreateForm(TfmMain, fmMain);
How to create new empty FireBird database using FreePascal/Lazarus
This is a very easy task in FreePascal/Lazarus.
Drop TIBConnection component from SQLdb page in a form or data module.
Drop a button, and write this code in button’s OnClick event:
procedure TForm1.Button1Click(Sender: TObject); begin IBConnection1.DatabaseName:= '/home/motaz/firebird/newdb.fdb'; IBConnection1.CharSet:= 'UTF8'; IBConnection1.UserName:= 'sysdba'; IBConnection1.Password:= 'masterkey'; IBConnection1.CreateDB; end;
This will create an empty FireBird database in the location you have specified in DatabaseName property, with UTF8 character set.
Later you can create tables, generators, indexes, and constraints using SQLQuery component example:
create table BOOKS ( BOOKID INTEGER not null , BOOKNAME VARCHAR(52) , CONTENTS BLOB, LOCATION VARCHAR(55) , constraint PK_BOOKS_1 primary key (BOOKID) );
This will create a new table called Books. You need to put this DDL script in SQL property of SQLQuery component that linked to your IBConnection.
Pascal language rating index for October 2012
I have noticed today that Pascal language rating index has been raised in Tiobe programming language index this month. It becomes number 14 which is very close to Delphi/Object Pascal in number 12. May be this has a relation to Lazarus version 1 release.
FreePascal/Lazarus book: Start programming using Object Pascal
This is a free PDF English book about Free Pascal / Lazarus for beginners.
Introduction
This book is written for programmers whom want to learn Object Pascal Language. Also it is suitable as a first programming book for new students and non-programmers.
It illustrates programming techniques as general in addition to Object Pascal Language.
License:
License of this book is Creative Commons.
Chapters:
- Language Basics
- Structured Programming
- GUI
- Object Oriented Programing
License: Creative commons
Lazarus Version 1 has been released
Lazarus team has announced the release of version 1.0 officially.
You can download it from one of these links:
http://sourceforge.net/projects/lazarus/files/
ftp://freepascal.dfmk.hu/pub/lazarus/releases/
Lazarus Web development: FreeSpider Apache Module
Yesterday I’ve released FreeSpider version 1.3.0 with support of Apache Module.
FreeSpider is a web development package that is used to develop web applications using Lazarus IDE.
Now it supports CGI executables and Apache Module library.
http://code.sd/freespider/index.html
You can migrate easily your old FreeSpider web CGI applications to produce Apache Module library version.
See performance comparison page:
http://code.sd/freespider/fsperformance.htm
Fore more detailed information please read the user manual:
http://code.sd/freespider/freespider.pdf
There are three web application samples in the page



Recent Comments