Saturday, December 22, 2012

Parallel Programming with OmniThreadLibrary: Synchronization

The “OTL book” has just been extended with a chapter on synchronization (22 pages). Basic understanding of synchronization issues and critical section usage is required as this chapter only deals with OmniThreadLibrary-specific support for locking.

Tuesday, December 18, 2012

OmniThreadLibrary ile Paralel Programlama*


Due to a strong language barrier we don’t hear from Turkish programmers much even though the programming (and Delphi) community in this big country is quite strong. That’s why I was pleasantly surprised when I received a proposal from that country to translate the OmniThreadLibrary book. We quickly set up a workflow (as the OTL book is still being written this is not a trivial task) and the book is now being translated.

Although I didn’t see more than a few translated paragraphs yet, I have great hopes that the initial Turkish release will join the ever growing family of the OTL books (English, Russian, Spanish) early next year. Until then, you can express the interest in the book here.

Great thanks go to Tugrul Helvaci for initiating the project and to Ramazan Gülbahar for translating the book!

* Parallel Programming with OmniThreadLibrary

Friday, November 23, 2012

DataSnap Speed & Stability

As the Roberto’s blog is not yet included in the DelphiFeeds concetrator, I’d like to bring to your attention his very interesting post: DataSnap analysis based on Speed & Stability tests.

Embarcadero Academy: Live Bindings

On Thursday, 29th I’ll be leading a workshop about LiveBindings and Visual LiveBindings in Ljubljana. The workshop will cover both XE2 and XE3 and will also cover differences between the VCL and FireMonkey implementation.

Predavanje bo v slovenskem jeziku. Prijavite se tu.


Sunday, November 11, 2012

FireMonkey2 in Ljubljana

Last week I spoke at FireMonkey2 workshop in Ljubljana. Attendance was low (compared to other “Embarcadero Academy” sessions) but very attentive and interested in the FireMonkey development.


Next session will be dedicated to LiveBinding (visual and nonvisual – both XE2 and XE3 will be covered) and is planned for 29. November. I’ll put a notice on my blog when a registration page is up.

Wednesday, November 07, 2012

OTL Repo Stable Again

Christian has finished the housekeeping tasks (days ago but I was busy and forgot to put a notice on the blog, sorry), so the repository is stable again.

Changes, with his own words:

  • introduced lib path (now all lowercase) to receive all DCU files separated by compiler, platform and configuration. The tests compile really quick now, without "polluting" the source directory with .dcu files
  • changed fastmm4 to fastmm, which is now an svn:external
  • added main icon for all tests (linked via MainIcon.rc resource script)
    • this still might cause linking issues on Delphi 2007, if compiled for the first time, but I will investigate this in the next days.
  • removed unused files and directories from the svn repository

Tuesday, October 30, 2012

Embarcadero Academy 2012: FireMonkey 2

Next week we (Embarcadero + Marand + me) are starting the next cycle of Delphi workshops. This time I’ll be talking about FireMonkey2 – about everything that is new & great in the latest release of this framework.
Predavanje bo – tako kot doslej – v slovenskem jeziku. Več podatkov dobite tu.

Monday, October 29, 2012

Welcome New OTL Committer!

Christian W. Budde has kindly offered to do a long-neglected housekeeping on the OmniThreadLibrary SVN tree. He now has committing rights and is already busy fixing .dproj files, SVN external references and other small things that I never have time to work upon.

The current state of the SVN tree may be as of this moment described as a ‘slightly unstable’ so checkout/update at your own risk. I’ll let you know when the rearrangements will have finished.

Sunday, October 28, 2012

Automagically Creating Object Fields with RTTI

While working on an internal project I came into a situation where a user (that is, a fellow programmer) would have to create a hierarchy of classes. As it turned out, this hierarchy would contain almost no implementation, just the class declarations, with one exceptions – every class would still have to be responsible for creating its children objects. Then I had a thought. Maybe I could use attributes and RTTI to do that in one central place instead of in every object.

Saturday, October 27, 2012


The ITDevCon 2012 is over and I’m back at home, resting and gathering impressions.

The conference was even better organized than previous years and everything was running as smooth as possible (with the small exception of the projector in the main hall, which somehow was not capable of giving out a completely sharp picture). In addition to the multinational group of speakers, the visitors also came from variety of countries – I noticed four Germans, two Russians and a Lituanian – which plays well with the intentions of making the ITDevCon the biggest European conference.

As usual, the conference took two full days, with five session timeslots on the first and six on the second day. At every time there were three parallel talks going on, some in Italian and some in English.

I’ve given three presentations – general tutorial on regular expressions and two “hands-on” sessions in problem/solution format – one on Windows + OS X development and another on OmniThreadLibrary. Slides and sample code are available on my blog.

I also listened to few sessions – both talks by Jeroen Pluimers were full of information and very useful; Ray Konopka’s session on user interfaces was incredible as always, Paweł Głowacki showed us what can be done with FireMonkey 3D components and Jørn E. Angeltveit gave interesting (WAT!) talk about the Smart Mobile Studio. I’m just too sory that I couldn’t follow Ray’s talk on creating custom controls for FireMonkey … Still, every session was recorded and participants will be able to get recordings of sessions they have missed. (By the way, recordings of last year conference are available on line.) I was also happy to finally meet Detlef Overbeek, the main guy behind the Blaise Pascal Magazine.

A quick shout to people that I haven’t yet mentioned – it was great to talk to you!

I would like to thank the organizer for inviting me again to the beautiful Verona and for all the great food we were able to taste in the two conference days (and at the pre-conference dinner). See you next year, guys!

Friday, October 26, 2012

Thursday, October 25, 2012

ITDevCon Photos

Just a few photo impressions from the conference …

bitTime Teambooksbooks2DanieleDetlefJeroenJornMarco, Pawel and Fabriziovisitors

Tuesday, October 23, 2012

Generating Reports with Background Worker

Long time ago, in August, JimVern asked on the OmniThreadLibrary forum:

I am creating a Windows Service to handle report requests for our clients.  Each client has multiple users who may run a report.  I want to serialize the report requests for one client so that only one report will run for a client at a time (FIFO), but reports can run simultaneously for different clients.

Since users can submit report requests anytime, I need to be able to append a new request to the end of an existing client FIFO queue without interrupting the execution of the current report.  Or, if the client doesn't have a queue yet (e.g., it's the first report request), then I need to be able to add a client queue without disrupting any reports running for other clients.  Once a client queue is empty, I want to destroy the client queue.

I am new to OTL, but it looks like it will easily do what I need. I'm just not sure where to focus my attention. Is there a way to create named task groups that can execute the top task of each group simultaneously, where tasks can be appended to an existing group, and where groups can auto-terminate when the tasks are all executed? Perhaps there an example project or a similar post that I can look at to get started? I'm still somewhat of a novice when it comes to threads, so any advise is also welcome.

My answer at that time was just a pointer in the correct direction:

Instead of running multiple tasks for one client, why don't you consider running one task per client and sending workload requests to that task?

You could then schedule each such task into a thread pool. The task would run in a loop and process requests. When it runs out of requests, it would shut down. The main program would be responsible for starting a new task if not already running. [There's a small race condition here - you would have to maintain a shared structure enumerating live tasks that would be modified from the task code and from the main program and it would have to be locked-accessed.]

I promised Jim a working solution but then I got lost in all sorts of other, more important projects and it was only few days ago that I was able to finish the job. Sorry, Jim :(

An example project is available in the OmniThreadLibrary repository in folder examples/report generator. This post describes the inner workings of that project.

Monday, October 22, 2012

Multiple Attributes on One Line

Apparently Delphi (at least XE2, didn’t test with others) allows you to write a comma-separated attribute list inside square brackets when annotating types and type members.

IOW, following two code fragments are identical.

[Description('Submodule 2.1)]
TModule2Sub1Info = class
[Name(CNameModule2Sub1), Description('Submodule 2.1')]
TModule2Sub1Info = class

I am not able to find if this is a documented behavior.

Tuesday, October 16, 2012

ITDevCon 2012 is almost here …

.. and I’m busy preparing my presentations. Come join me in Verona and listen to following talks:

Regular expressions - friend or foe?

Regular expressions are one of the most underused features of the Delphi RTL. While in the past we could attribute this to the lack of built-in support, Delphi XE introduced the RegularExpressions unit which greatly simplifies the use of the regular expressions engine. This session will present basic ideas behind the regular expressions, examine the RegularExpressions unit and in particular the main workhorse - the TRegEx class - and continue with practical examples which will show how and when to use regular expressions - and particularly when to stay away from them.

"Hands On": Parallel programming with OmniThreadLibrary

In the past few years, OmniThreadLibrary has become "de facto" standard for Delphi multithreaded programming. Still, the main stumbling block for programmers to "go multithreaded" is the grasp of patterns and practices for multithreaded development. This "hands on" session will take different practical examples, deconstruct them into basic operations and then show how to build simple parallel solutions based on the initial analysis.

"Hands-On": Developing for Windows and OS X

Multiplatform development is slowly taking hold in the Delphi world. While we can argue that the tools for the mobile platform are still in the infancy stage, the situation on the desktop is quite different. Delphi is a valid development tool for the OS X-based computers. The main topic of this session will be hassle-free multiplaftorm development - how to write your code that it "simply works" on both platforms and what to do when this is not possible.

(That is, if you’ll not be listening to other great presentations running at the same time!)

Friday, October 12, 2012

Programación Paralela con OmniThreadLibrary

Bookpage?1350027408The OTL book is now available in Spanish language!
Big thanks to jachguate who translated the book.

Finalmente, ¡aquí está la primera entrega del libro!.
  • Actualizada a la versión en Inglés publicada el 8 de octubre de 2012.
  • Adaptado a la versión 3.02 de OTL.
Contiene el contenido completo de los capítulos:
2. Introducción a MultiThreadLibrary
3. Multi-hilos de alto nivel
7. How-to
Al comprar el libro, recibirás todas las actualizaciones futuras completamente gratis.

Gracias por el interés mostrado en adquirir el libro.

Juan Antonio Castillo y Primož Gabrijelčič

Monday, October 08, 2012

OTL Book Update

A minor update of the “OmniThreadLibrary Book” has been released.
  • Adapted to the OmniThreadLibrary 3.02 release.
    • Documented background worker initializers and finalizers.
    • Documented Async/Await abstraction.
  • Fixed minor problems found by [jachguate].
Update [2012-10-09]: Russian translation has also been updated.
Update [2012-10-12]: Spanish translation has been released.

Rarely Seen in the Wild

I don’t believe many of you had opportunity to observe this error before.


Wednesday, October 03, 2012

Programación Paralela con OmniThreadLibrary

otl_esIt’s official – Parallel Programming with OmniThreadLibrary is being translated into Spanish!

The translator, Embarcadero MVP Juan Antonio Castillo Hernández a.k.a. jachguate, is already working on the book. I hope we’ll have first (partial) translation ready soon.

Until then you can express the interest in the book on the LeanPub site.

OmniThreadLibrary 3.02 released

OmniThreadLibrary 3.02 was released today. This is mostly a bugfix release with few new parts (XE3 support, Async/Await). Update is strongly recommended for everybody.
Get it as a zip or from the svn.

Monday, October 01, 2012

Smart RTL

I have just published an update (63 new pages!) to A Smart Book. New topics cover important parts of the RTL libraries – graphics (HTML5 canvas), regular expressions, browser storage, accelerometer, touch and gesture, layout manager and networking (HttpRequest and JSONP). Also added was a new section on running code on application shutdown (in the Programming with Smart chapter).

Click here for more information about the book …

Wednesday, September 26, 2012

The OTL Book has 100 readers!


Thanks to everybody who bought the book! Your contribution to the OmniThreadLibrary project is much appreciated!

And not forget the Russian book owners. There are only 17 of them at the moment but their contribution is appreciated nonetheless. (And, again, thanks to Alex Egorov who is translating the book into Russian.)

Tuesday, September 25, 2012

OmniThreadLibrary and XE3

Just a quick notice – SVN HEAD works fine with XE3. I’m cleaning up some old issues and will be releasing new version over the weekend (most probably).

Sunday, September 23, 2012

XE3: Internal Error G9413

Today I wanted to check whether the OmniThreadLibrary plays nice with XE3 (yes, I know, I’ve should have done this weeks ago, but there was simply not enough time) and I was completely surprised when OtlSync unit couldn’t be compiled due to an internal error G9413.

One hour later I have reduced the problem to a simple test case (below) and to a simple fix. So the OmniThreadLibrary will be supported in the XE3 (as we all hoped for).

For other poor souls that may have run into this problem, here’s a small test case and a workaround.



TTest<T> = class
procedure Test;

a: IInterface;

procedure TTest<T>.Test;
aMethCreate: TRttiMethod;
if Length(aMethCreate.GetParameters) = 0 then


a := nil; // F2084 Internal Error: G9413

The problem here is that the G9413 internal error is not reported on the line which causes the problem. The real culprit here is the ‘if Length(aMethCreate.GetParameters)’ call in the ‘TTest<T>.Test’ method.

To fix the problem it is enough to introduce a temporary variable that stores the result of the GetParameters call.

unit Unit136;




TTest<T> = class
procedure Test;

a: IInterface;

procedure TTest<T>.Test;
aMethCreate: TRttiMethod;
params : TArray<TRttiParameter>;
params := aMethCreate.GetParameters;
if Length(params) = 0 then

a := nil;

The problem is reported as QC #108942.

Tuesday, September 18, 2012

XE3 World Tour in Ljubljana


100+ people arrived. Presentation went through without big glitches and audience was very helpful when I managed to mess things up. Thanks, folks!

Friday, September 14, 2012

Don’t Miss XE3 Event in Ljubljana!

Only four days are left until the XE3 event in Ljubljana! I’ll be showing all that is new in RAD Studio XE3 including (but not limited to) FireMonkey2, Visual LiveBindings, Windows 8 development and HTML5 Builder.

Follow this link for registration and to see the detailed timetable.

A special notice for all friends – reserve some time for a beer or two after the presentation ;)

Wednesday, September 12, 2012

Parallel Programming with OTL [RU] Update

The always hard-working Alex has translated all the new material from the OTL book so now the Russian and English version are again in sync.

Thanks for all the work, Alex!

Thursday, August 23, 2012

Parallel Programming with OmniThreadLibrary–How-tos

Good news for all OmniThreadLibrary fans – the long-awaited How-to chapter has been published.

Following topics are covered:

  • Background File Scanning
    Scanning folders and files in a background thread.
  • Async/Await
    How to write 'blocking' multithreaded code with a mechanism similar to .NET's `async`/`await`.
  • Web Download and Database Storage
    Multiple workers downloading data and storing it in a single database.
  • Parallel For with Synchronized Output
    Redirecting output from a parallel for loop into a structure that doesn't support multithreaded access.
  • Background Worker and List Partitioning
    Writing server-like background processing.
  • Parallel Data Production
    Multiple workers generating data and writing it into a single file.
  • Building a Connection Pool
    Using OmniThreadLibrary to create a pool of database connections.
  • QuickSort and Parallel Max
    How to sort an array and how to process an array using multiple threads.
  • Parallel Search in a Tree
    Finding data in a tree.
  • Multiple Workers with Multiple Frames
    Graphical user interface containing multiple frames where each frame is working as a frontend for a background task.
  • OmniThreadLibrary and Databases
    Using databases from OmniThreadLibrary.
  • OmniThreadLibrary and COM/OLE
    Using COM/OLE from OmniThreadLibrary.

Other changes and additions:

  • Added Release Notes section.
  • Fixed image sizes and line breaks in the High-level Multithreading chapter.

I will now spend few weeks finishing the Smart RTL chapter of the A Smart Book and then I’ll return to the Parallel Programming with OmniThreadLibrary. In the meantime you can express your interest in missing chapters in the poll on the right side of this blog.

Tuesday, August 21, 2012

XE3 in Ljubljana

The Ljubljana stop of the XE3 World Tour will occur on September 18th.

Register here (not yet linked from the World Tour page).

This year I’ll be doing the presentation. I’m already looking forward to that!

Tuesday, July 31, 2012

Async/Await in Delphi

Let’s assume you’ve inherited this pretty useless code.
procedure TForm125.Button1Click(Sender: TObject);
  button: TButton;
  button := Sender as TButton;
  button.Caption := 'Working ...';
  button.Enabled := false;
  button.Enabled := true;
  button.Caption := 'Done!';

Now, your boss says, you have to make it parallel so the user can start three copies of it. (You also have to add two new buttons to the form to start those instances but that’s easy to do.)

Tuesday, July 17, 2012

Параллельное программирование с OmniThreadLibrary

Alex did the impossible and translated all existing parts of Parallel Programming with OmniThreadLibrary in a record time! The Russian version of the book is now on sale at LeanPub.

Параллельное программирование с OmniThreadLibrary

Click here for additional information about the book…

Monday, July 16, 2012

Programming with Smart

Today I have published a new chapter in A Smart BookProgramming with Smart. Inside you’ll find:

  • My First Smart Program
  • File Management
  • Application Architecture
  • Forms and Navigation
  • Message Dialogs
  • Themes and Styles
  • Command-line Applications
  • Writing Games

Click here for more information about the book …

Tuesday, July 10, 2012

Параллельное программирование с OmniThreadLibrary *

bookpage[* Translation: Parallel Programming with OmniThreadLibrary]

Fellow programmer Егоров Александр (Alex Egorov) has offered to translate the OmniThreadLibrary book into Russian.

As the original book, it will be published on the LeanPub. Current plan is to make it available after the High-level multithreading chapter is translated. At the moment, you can download the first draft which contains translated Introduction.

You can express your interest in the book here.

Sunday, July 08, 2012

Introduction to OmniThreadLibrary

The Introduction to OmniThreadLibrary chapter is completed. New version of the book has already been published and all buyers have been notified by the email.

Wiki will be updated soon.

Please remember – the best way to support the OmniThreadLibrary project is to buy the book!

The next chapter will be either Synchronisation or How-to. I’ll give you few more days of voting time to decide the matter.

Friday, July 06, 2012

New Poll

There’s a new poll available – look to the right and you’ll see it.

If you have any preferences on what you want to read in the Parallel Programming with OmniThreadLibrary next, please vote.

Thursday, July 05, 2012

High-level Multithreading

Chapter five of my book Parallel Programming with OmniThreadLibrary is now completed. New version of the book has already been published and all buyers have been notified by the email.

Wiki will be updated soon.

Please remember – the best way to support the OmniThreadLibrary project is to buy the book!

The next chapter on the list is Introduction to OmniThreadLibrary which won the public poll by a very small margin (34 votes against the 31 votes for the Synchronisation chapter).

Smart Controls

Today I have published new version of the A Smart Book.

Newly added chapter Smart Control on 54 pages covers all built-in controls, from TW3Panel to TW3Header. Additional sections include tips on writing custom controls and description of the TW3ScrollControl control.

Sample book was also extended. In addition to Smart Pascal and Regular Expressions chapters it now contains selected parts from the Smart Controls chapter, including full text on TW3EditBox and TW3Toolbar.

Click this link for more information about the book …

Wednesday, July 04, 2012

OmniThreadLibrary Documentation: Blocking Collection

A chapter on blocking collection (IOmniBlockingCollection) is now available online.

Tuesday, July 03, 2012

OmniThreadLibrary Documentation: ForkJoin

A chapter on Parallel.ForkJoin is now available online.

Better OnStop

Pop quiz! What’s wrong with this code?

  FPipeline1 := Parallel.Pipeline
procedure (const input: TOmniValue; var output: TOmniValue)
procedure (const input: TOmniValue; var output: TOmniValue)
Caption := 'All done';
FPipeline1 := nil;

Thursday, June 21, 2012

Parallel Programming Poll Extended

While setting up the poll on the right I did something wrong and it was prematurely closed.

This has now been corrected – you can again vote for your favourite.

Monday, June 18, 2012

Hacking FastMM for Debugging Purposes

Last week I started solving weird ‘out of memory’ crash in one of our services. First reports of problems came in from a client but with some experimenting I managed to repeat it on the test configuration. The program works nicely for few hours and then something weird happens and it starts using the memory, few megs per minute, until it crashes.

Repeating the problem on the test configuration usually means half the victory won but this time it wasn’t so :( I was fighting the most terrible of memory leaks – a live leak. Memory was allocated, stored away in some management structure and properly disposed off when the program terminated. FastMM have shown no problems at all. Such problems are always hard to find.

Saturday, June 16, 2012

Delphi Foundations

Chris Rolliston has published his monumental[*] work “Delphi XE2 Foundations” in Kindle format (paper version to follow). The book is split in three parts (TOC is provided in the book home page), each priced at £7.99/€8.99/US$9.99 (which of course translates to $13.79 for people not living in USA, UK, DE, FR, ES or IT – damn Amazon!). As the book is excellent, the price is more than fair – if you doubt my words, download the sample from the Amazon.

As the book site is called “” and not “” I can’t but assume that Chris will update the book to following Delphi releases, which would indeed be a great thing.


[*] It is hard to tell book size from the Amazon’s download size but I have read Chapter 15 (Multithreading) in advance and I can attest to the fact that it is a) very long and detailed, b) very exhaustive and c) very well written.

Tuesday, June 12, 2012

The Book is Here!

I have finally pushed the Publish button and “The Book” is now available on LeanPub.

To get the current book status, click here or on the book cover image right to this post.

If you want to affect the order in which the book is written, participate in poll on the right (below the book cover image). I will complete the “High-level Multithreading” chapter regardless of your votes but then I’ll follow the majority.

Monday, June 11, 2012

Thursday, June 07, 2012

Parallel Programming with OmniThreadLibrary – Current Status

Parallel Programming with OmniThreadLibrary is now complete. It will be updated as the OmniThreadLibrary itself is updated, but other than that it is done.

Go to LeanPub to learn more about the book, read the free sample or buy your own copy!

Tuesday, June 05, 2012

When a Hotfix Requires a Hotfix

Do you know that feeling when you can’t put together a simple piece of code? You turn it around and around and there’s always “one last” problem. Even after you’ll happy with it, the first user that tries it out will find a problem. And then you correct that and you’ll happy with it again and the first user that tries it now will find a new problem. :(

It looks like I’m playing this game with Parallel.Join. I can’t make the @#$%^ thing to work correctly. That’s why I have just issued another hotfix. If you are following the SVN head, just do the Update. Otherwise, please download the updated OtlParallel unit.

Thanks go to [meishier] for reporting the problem!

Sunday, June 03, 2012

A New Web, a New Book and a New Info Source

I have decided to start up a new blog, dedicated to programming with Smart – If you are using the Smart Mobile Studio or if you think that programming mobile applications with Pascal is an interesting idea, make sure to bookmark it.

I will however not move all my Smart-related posts there, most important stuff will also be published here.

My book about the Smart is now available – read more in my post on the new blog. [But feel free to comment here, if you want.]

And the last but not least – I have created a Twitter account. (Took me a long time, I know.). Follow me @thedelphigeek and you’ll get notifications about the OmniThreadLibrary, A Smart Book and more.

Parallel.Join hotfix

There was a nasty bug in Parallel.Join which (sometimes) raised its ugly head when number of tasks submitted to the Join abstraction was larger than the number of parallel execution units (threads). Big thanks go to [Passella] for reporting the problem together with a reproducible test case.

If you are following the SVN head, just do the Update. Otherwise, please download the updated OtlParallel unit.

Tuesday, May 22, 2012

Sunday, May 20, 2012

A Smart Book

Yes, there will be a book about the Smart Mobile Studio. I don’t know yet how it will be published – as a printed manual that you’ll get together with the software, as an on-demand printed book, as an e-book or combination of those options – but there definitely will be a book about Smart.

For starters, you can download test chapter (not yet completely finished) about using regular expressions in Smart: PDF, Mobi, ePub (rename it to .epub after download). If you like what you see, you can express your interest in the book at the Leanpub site.

On a slightly unrelated topic – I’m thinking about moving all my writing about Smart to another, yet unnamed blog. However, I’m of two minds about this so I would appreciate a feedback. What do you think – should I create a new blog or should I write about Smart here (after all, it uses almost the same language as the Delphi)?

Saturday, May 19, 2012

OmniThreadLibrary Documentation: BackgroundWorker

A chapter on Parallel.BackgroundWorker is now available online.

Laying out Smart applications with Layout Manager [4]

Last time you’ve seen how to make different layouts for portrait and layout orientations. This time I’ll show you how to dynamically set layout parameters in Resize.

Friday, May 18, 2012

OmniThreadLibrary Documentation: ParallelTask

A chapter on Parallel.ParallelTask is now available online.

Laying out Smart applications with Layout Manager [3]

The third layout manager demo shows how to set different layouts for portrait and landscape display orientation.

Thursday, May 17, 2012

Embarcadero Academy–The Multithreading Session

I spoke to Slovenian Delphi developers about multithreading today and you probably know that this is a topic I love to speak about. The room was packed (I took this photo five minutes before the beginning, more people arrived after that) but still listeners managed to stay attentive through the four-hour session (including a short break). Lots of interesting questions too – it is good to see many developers actively interested in multithreading.

We’ll probably repeat this session in the autumn as again there was much more interest for the speech than this room can handle.


Laying out Smart applications with Layout Manager [2]

The second layout manager demo builds on the first one.

There’s an edit box and two small buttons right to it. A large button lies under all three of them. At the bottom of the screen is a status bar and all the rest is taken by a memo control.

Wednesday, May 16, 2012

Laying out Smart applications with Layout Manager [1]

Smart Mobile Studio was released today. To celebrate this – in my opinion – very important step for the Object Pascal language, I have prepared a series of articles on the Layout Manager – a feature of the Smart RTL that I wrote.

Smart is an excellent tool, but in some areas it clearly shows that there was only so much time allowed for the development. I’m sure Lennart will polish the rough edges in next releases but for now we have to do with what we have.

One of those rough edges is component placement. You can drop components on the designer and set their size but there’s no mechanism for dynamic size adjustments. In other words – there is no Align, no Anchors, no Margins and no layouts (as TFlowPanel and TGridPanel in Delphi). We have to resize components in code, in the overloaded Resize method.

I quickly got sick of writing resizing code and decided to alleviate the problem by writing a layout manager. It does not work in the designer, you have to declare and use it in code, but still it is a big simplification over the default “just call SetBounds from Resize” approach. I donated layout manager to the Smart project and it is included in the 1.0 release as the w3layout unit.

This article starts a short series which will explain layout manager on simple examples. All of those examples are also included with the Smart installations (look in Demos, LayoutManagerDemo).

Thursday, May 10, 2012

SmartMS Demos

The Smart Mobile Studio is nearing its release date (no, can’t tell you when, but it will be soon, really soon) and it’s time to revisit my demos. You test them all from my website (just click on the images) and access the source code. If you don’t (yet) have Smart, you can browse OPP file with my primitive OPP Browser.



Accelerometer-handling demo (iOS only). Move the square by tilting the device.

article, source

Game of Life


Conway’s Game of Life. Works on desktop and on tablets. Click in the gray rectangle on the left to open a library of building blocks then drag and drop a block on the game surface.




Gesture-handling demo (iOS only). Handles move, zoom and rotate.


Mandelbrot Explorer


Mandelbrot explorer. Works on device (at least on iPad) and on desktop.

article, article, source

Multi Finger Paint


Paint with multiple fingers (iOS only; single finger may work on Android). Also handles mouse on desktop.

article, source



Tic-tac-toe game.




No IDE is mature until it has a TSmiley component. Supports desktop and mobile. Click/touch to change TSmiley’s mood.

article, source

Tuesday, May 08, 2012

Delphi-Tage 2012

Incidentally, I’ll be in Germany just when the Delphi-Tage 2012 will be going on and I'll be staying fairly close (in Nürnberg). Is there any interest amongst my German readers in me presenting a session on multithreading there?

Sunday, May 06, 2012

Embarcadero Akademija: Multithreading

This is an announcement for the next “Embarcadero Academy” session. This time I will be talking about my favourite topic – multithreading. As the previous two sessions (Unicode, FireMonkey), this one is intended for the Slovenian Delphi programmers. The rest of my post is directed to potential participants and is therefore written in the Slovenian language.

Monday, April 23, 2012

GpDelphiUnits update

As always, all units are available on Google Code.

DSiWin32 1.66

  • Implemented DSiSetFileTime and DSiSetFileTimes.
  • Implemented DSiDateTimeToFileTime.
  • TDSiRegistry.ReadBinary, WriteBinary now use RawByteString for data buffer.

GpHugeF 6.05

  • Added logging to TGpHugeFile[Stream].

GpStreams 1.39

  • Added function CopyStreamEx accepting a TStreamProgressEvent.

GpStringHash 1.11

  • TGpStringObjectHash.Find returns 'nil' in 'value' parameter if key is not found.

GpTextStream 1.10

  • Implemented TGpTextMemoryStream, a TGpTextStream wrapped around a TMemoryStream.

Saturday, April 21, 2012

OmniThreadLibrary 3.01 released

This is mainly bugfix release with only few additions to the codebase. If you are using version 3.0 and not following the SVN trunk, update is very much recommended.
Get it now: ZIP, SVN.

Friday, April 20, 2012

OmniThreadLibrary Documentation: Join

A long chapter on Parallel.Join has been added to the wiki.

All book material is now also available in the Markdown format in the SVN.

I have started putting together “the book”. The plan is to release early – most probably when all high-level stuff is covered – and then to regularly publish updates. Updates will always be free for all customers. At the moment you can’t preorder the book but you can express your interest at the link above.

Sunday, March 25, 2012

How do you build FireMonkey iOS applications on Lion?

Delphi uses FPC 2.6.0 to do the iOS compilation.


I have Xcode 4.3.1 installed (no idea why the version is not displayed in the list).


FPC 2.6.0 doesn’t recognize it. Apparently it only works with Xcode up to 4.2.


Apple only offers XCode 4.3.1 for Lion.


So I’m asking you – can I really use Lion to compile FireMonkey iOS applications? Doesn’t seem so.

Sad smile

Friday, March 23, 2012

Running FireMonkey applications on OS X 10.7.3

I have big problems with FireMonkey applications not running on my new Mac Mini. Does anybody have any information about any possible incompatibilities between XE 2 Update 4 and OS X 10.7.3?

Full problem description is on StackOverflow.

This problem is connected to the Thread Status window. If you have this window visible in the Debug desktop, Delphi will lock when you try to run an OS X application in the debugger. Removing Thread Status window from the Debug desktop solves the problem.

Interestingly, some installations of XE2 Update 4 are working just fine even when Thread Status window is visible.

Wednesday, March 14, 2012

Embarcadero Akademija: FireMonkey

This is an announcement for the second “Embarcadero Academy” session. As the previous one, it is intended for the Slovenian Delphi programmers. The rest of my post is directed to potential participants and is therefore written in the Slovenian language.

Thursday, March 08, 2012

Unicode in modern Delphi applications

The first “Embarcadero Academy” session was a huge success. More than 40 people were present (we had to cap the participants as the venue don’t allow for larger audience) and as far as I could tell from all the direct and indirect feedback they were very satisfied with the three-hour Unicode presentation.

The topic of the next workshop will be FireMonkey. See you on March the 29th!

Sunday, February 26, 2012

Embarcadero Academy

In 2012, Embarcadero with the help of Slovenian distributor Marand is preparing a series of presentations, focused on different aspects of Delphi programming – Unicode, FireMonkey, multiplatform development, Object Pascal as a modern programming language, debugging, multithreading and more. Presentations will be given in Slovenian language by yours truly. The rest of my post is directed to potential participants and is therefore written in the Slovenian language.

Friday, February 24, 2012

Exceptions in Async

Pop quiz time! What would the user see if this code is executed in your application?

raise Exception.Create('Exception in Async'); end);

The answer may surprise you: Nothing! At least if you’re not using the latest SVN version.

Wednesday, February 22, 2012

Introduction to Debugging

Blaise Pascal Magazine #21 is out with with my introductory article on debugging. Two more advanced articles on the same topic are scheduled to follow.

Tuesday, February 21, 2012

Accelerometer Revisited

I wrote about handling accelerometer in iOS from the browser before (Detecting Device Movement, Accelerometer Demo) but I wasn’t happy enough with my code and I promised to return with the third part. Today I returned to the topic with advanced features – handling data smoothing and calibration.

Monday, February 20, 2012

Sunday, February 19, 2012

Blaise Pascal Magazine Rerun #9: High Level Multithreading

This article was originally written for the Blaise Pascal Magazine and was published in Issue #18.
Relevant Delphi code is available at

Saturday, February 18, 2012

Friday, February 17, 2012

OmniThreadLibrary Documentation: Future

I have just finished a pretty long chapter on futures.

Any comments, corrections, ideas etc are welcome.

8 Simple Rules for Modifying Production Database

  1. Make sure you have a backup!
  2. And by that I mean a fresh backup, made just now, not an idea that there may exist a person who knows where a backup is stored!
  3. Make sure you can restore from the backup!
  4. And by that I mean that you have tested the restore procedure. On the backup that you have just created. And that you have tried accessing restored backup with the program that usually operates on it!
  5. Don’t type any SQL commands. Use only scripts/programs that were previously tested on a development/test database.
  6. And by that I mean tested by yourself, not by a fictitious somebody who may have tested a script three years before on a database used by a completely different program!
  7. Don’t modify production database!

Thursday, February 16, 2012

Tuesday, February 14, 2012

Monday, February 13, 2012

Blaise Pascal Magazine Rerun #5: Four Ways to Create a Thread

This article was originally written for the Blaise Pascal Magazine and was published in Issue #10.
Relevant Delphi code is available at

Blaise Pascal Magazine Rerun #4: Introduction to Multithreading

This article was originally written for the Blaise Pascal Magazine and was published in Issue #9.

Friday, February 10, 2012

Accelerometer Demo

My accelerometer blog ended rather abruptly, without a demo program so today I’m returning to the topic.

To test the accelerometer control I wrote a very simple program in which you can move a rectangle around the screen by tilting your iOS device. You can test it here.

This program builds heavily upon the source code I found on Alberto Sarullo’s blog. Thanks!

Wednesday, February 08, 2012

OmniThreadLibrary Documentation: Async

First small part of the forthcoming documentation is available in the wiki, Any comments, corrections, ideas etc are welcome.

Tuesday, February 07, 2012

Detecting Device Movement

For my next quest I decided to find out how accelerometer works in web applications. IOW, I wanted to control an object on my HTML page just by moving my iPad around.

I limited my quest to iOS because that’s my favorite toy. don’t know yet how to do it in Android – this StackOverflow post hinted that access from bare JavaScript may not be possible. PhoneGap somehow does that, but it’s quite possibly that they implement Java wrapper that exposes native accelerometer data to your JavaScript. But that’s just guessing.

Thursday, February 02, 2012

Wiki Editing

Is there a Windows application that simplifies editing of Wiki-formatted documents? I would settle for a very basic one - all formatting can be displayed in wiki format on screen but I would like some helpful shortcuts and logic that would simplify multilevel list editing, basic formatting, cross-document linking etc.

Do you have any recommendation? I'm sick of using Notepad2 for these purposes.

In case there's no such tool available - is there a young programmer that needs a pet project? Put together a TSynEdit (to bring in highlighting and printing) and a toolbar/ribbon and you'll be half done...

Tuesday, January 31, 2012

OmniThreadLibrary Documentation–an Outline

That’s how it’s going to look. If you feel I have left something out, now is the time to raise your voice.

Saturday, January 28, 2012

A Sign of Maturity

No IDE is mature until it has a TSmiley component.

This week I got a sudden urge to write TSmiley component for Smart Mobile Studio IDE. After all, what is a development environment without a smiley?

My TSmiley is not an enterprise-y solution like latest Nick’s revisit of the old theme ;), oh no, it is a lean and mean component without any special bells and whistles. You can select the smiley’s emotion and it will change the look. And that’s it.

I thought that a story about TSmiley for Smart would be instructive for you, dear reader, as this is almost the simplest component one can write. Read on to see how writing a component for Smart is very similar to writing a component for Delphi and how it is also utterly different.

GpDelphiUnits update

Although I’m regularly pushing updates into Google Code repository, updates to my web pages and, incidentally, to my blog are dragging behind. Here is the last year worth of changes:

Friday, January 20, 2012

Handling Touch Events

I mainly started playing with the Smart Mobile Studio because I wanted to write some stuff for my iPad. OK, there’s a small issue of possibly producing client applications for my job and maybe for some freeware/shareware stuff I’m thinking about, but this is not on the horizon yet. Therefore, iPad. (And I don’t have iPhone and I don’t care about writing stuff for my wife’s Android, so – iPad.) And writing for iPad means supporting touch gestures.

[Yes, I know I could use Objective-C but – bleuch, really? – and I could use FireMonkey but I don’t have a Mac and don’t want to buy one just for playing around and I can’t make Platform Assistant run in a Hackintosh, Therefore, Smart.]

Touch is natively supported in Smart. Gestures are not (but that may change before the release). What’s the difference, you ask? Touch subsystem will give you information about separate fingers like – finger has touched – another finger has touched – first finger was moved – both fingers were moved – while gesture subsystem will give you a simple – zoom gesture in progress. But hey, let’s start with touch. Lots and lots of stuff can be written with just the information about the fingers touching the screen.

Tuesday, January 17, 2012

Improved Painting

When I wrote about my first Smart Mobile Studio program I mentioned that it failed on iPad (and would probably fail on iPhone too but I couldn’t test that) because the Paint code took too long and the iOS simply aborted it. As far as I know there are two ways to fix this in JavaScript – you can either move the calculation to a background thread using a Web worker mechanism or split the Paint into multiple parts where each part only calculates and paints small part of the screen and then returns control to the browser. For the time being I went with the latter solution but that will not prevent me from testing the Web worker approach at some time.

OmniThreadLibrary in Practice [2a]–Backround Worker and List Partitioning

Today I’m revisiting example from November 2011. This time I’ll solve it using the new Parallel.BackgroundWorker abstraction.

Part of the Zarko’s requirements (see the original post for full text) was a cancellation support.

At any time the "master" thread could be signaled to terminate (from the app's main thread) all child threads (and itself).

When I was originally implementing this using the Parallel.Pipeline abstraction I had to put some work into the cancellation support. The main reason for this was inappropriate abstraction – Parallel.Pipeline is designed around the data flow processing and supports only a basic cancellation of the “stop everything” type. To be fair, that would comply with the Zarko’s requirements, but I wanted nicer solution where you can stop processing and then continue with a new work item without rebuilding the background thread mechanism. [Pipeline solution inherently supports cancellation but you cannot recover from it – to continue processing one would have to destroy the pipeline and build a new one.]

Tuesday, January 10, 2012

Background Worker

When I wrote OmniThreadLibrary in Practice [2]–Background Worker and List Partitioning in November, I noticed that OmniThreadLibrary needed another high-level abstraction, a background worker. I published some ideas on how the background worker interface could look. Those ideas were later developed in a full-fledged high-level solution.

Background worker is designed around the concept of a work unit. You create a worker, which spawns one or more background threads, and then schedule work units to it. When they are processed, background worker notifies you so you can process the result. Work items are queued so you can schedule many work items at once and background thread will then process them one by one. [Actually, Parallel.Pipeline is used as a base for the implementation.]

Handling Mouse Events in Smart Mobile Studio

After I finished my very first Smart program, I wanted to enhance it with some interactivity. I wanted the user to be able to navigate through the Mandelbrot set by using mouse and touch. For now, I have only implemented the mouse part, touch events will be handled later (soon, I hope).

I wanted to achieve few different ways of navigation:

  • Click & drag with the left mouse button shows a rectangle on the screen. When the mouse button is released, program zooms in to display the selected rectangle.
  • Double-clicking zooms in around the point of click.
  • Right-clicking zooms out around the center of the image.
  • Right-click & drag shows a line on the screen. When the mouse button is released, program moves the current view (point of first click is moved to the point of release).
  • If a drag operation is in progress, user can click and release the other mouse button (left if right-drag is in progress, right if left-drag is in progress) to cancel the drag operation.

You can see the navigation in action in this (very low quality, sorry) YouTube video.

Saturday, January 07, 2012

My First Smart Program

Last week I wrote about my first impressions about the OP4JS/Smart Mobile Studio project. This week I’ll show you my first program.

Wednesday, January 04, 2012

First Steps with Smart Mobile Studio

“JavaScript is Assembly Language for the Web” 
[original author unknown]
I learned about that idea from the omnipresent Hanselmann and I fully agree with it. JavaScript has its good moments, but they are completely outweighed by the total mess and confusion that is the JavaScript language and by some awful decisions made by the original designer.
If you don’t believe me, try answering the following question. “What does JavaScript expression ++[[]][+[]]+[+[]] evaluate to?” I’m not kidding you – this mix of plus signs and square brackets is a legit JavaScript expression and its result is ‘10’. [For proof, see Stackoverflow question Can you explain why ++[[]][+[]]+[+[]] = 10.]
As you may have guessed, I don’t like programming in JavaScript. I can read it on a good day but I never managed to write more than few lines of JavaScript code. On the other hand, I would like to write a browser application from time to time, as that would allow me to run such an app on different platforms (and by that I mean a PC, Mac, iOS, and Android).
When I learned about the OP4JS project, which promised a cross-compiler from Delphi-like language to a JavaScript and an integrated development editor, I was almost ecstatic with joy. Truly, such a tool would be a great addition to my toolset – if the authors managed to pull it through. It looked like a tough project for just two people. But … as the Lennart (one of the authors) likes to say – one good Delphi developer is worth hundred mouse-pushers (or something to that effect). They struggled and they succeeded. Just before the end of 2011, select few people received the alpha version of the IDE so that we could play with it over the holiday season.
I’ve got the permission from the authors to write about it so in the next weeks you can expect posts that will follow my road to Delphi-generated HTML+JavaScript applications.