December 19, 2012

Lambdas in Smart–Why does this make me happy?

Smart 1.1 will support the lambda syntax. Why is this a big deal?

It’s simple.

This is the old code:

  ResizeChildren(FClientArea.Height, [TAlign.Top, TAlign.Bottom],
function (layout: TLayoutImpl): Variant
Result := layout.GetConfig.GetHeight;
procedure (layout: TLayoutImpl; value: integer)

And this is the new code:

  ResizeChildren(FClientArea.Height, [TAlign.Top, TAlign.Bottom],
lambda (layout) => layout.GetConfig.GetHeight,
lambda (layout, value) layout.GetConfig.Height(value) end);

Is this a good enough reason to be happy? I think it is!

December 11, 2012

“The Sons of Kahn and the assembly language of the internet”

Verity Stob follows the SmartMS development! Yeah!

“Then the users of Delphi parleyed among themselves. And some were for adopting tools such as Smart Mobile Studio and Elevate Web Builder which taketh Pascal and compile it to filthy JavaScript-that-is-the-assembly-language-of-the-internet.”

November 09, 2012

A Taste of Things to Come

While there’s not much going on in public, lots of talented people are working on the next Smart Mobile Studio release.

For a taste of things to come, here are two demos of the new component – TW3ListBox: ListBoxControl, ColorListBox.

First demo supports rearranging items by mouse/touch. Just click/press an item and hold the button/finger down for a second. An item will change color and you’ll be able to drag it to a different place.

While testing ListBoxControl you’ll notice that listbox items are not jumping around; they are softly sliding from a place to a place. You will also be able to create such interfaces by using a new animation unit. You can test the demo program for this unit here: ControlAnimation.

FYI, the code behind this demo fits on one 80x25 screen.

procedure TForm1.InitializeObject;
{$I 'Form1:impl'}
W3Button1.OnClick := StartMoving;

procedure TForm1.StartMoving(Sender: TObject);
W3Button1.Caption := 'Stop!';
W3Button1.OnClick := StopMoving;
var right := ClientWidth - W3Button1.Width;
var bottom := ClientHeight - W3Button1.Height;
Animation[W3Button1].Rotate(2000, 360, 0, Animation.Config.SetLoop(true));
Animation[W3Button1].Move(10000, [0, 0, right, 0, right, bottom, 0, bottom, 0, 0],
Animation.Config.SetOnCompleted(procedure begin StopMoving(nil); end));

procedure TForm1.StopMoving(Sender: TObject);
W3Button1.Caption := 'Click me!';
W3Button1.OnClick := StartMoving;
if assigned(Sender) then begin // not called from the end-of-animation handler
Animation[W3Button1].Move(100, 0, 0);
if W3Button1.Angle = 360 then W3Button1.Angle := 0
else Animation[W3Button1].Rotate(100, W3Button1.Angle, 0);

October 20, 2012


I have to apologize to all my readers – I have comment moderation turned on for old posts and I didn’t set my email address in the Blogger setting. Because of that I didn’t receive any comment moderation notifications and as I almost never check the Blogger site, I didn’t notice that seven comments got caught in that filter :(

The comments are now published (although they are very outdated). Sorry for that – I’ll be getting notifications in the future.

A note for Thomas who has problems buying my book – sorry but you’ll have to sort this out with the LeanPub.

October 01, 2012

Smart RTL

A Smart Book has been updated again! New chapter Smart RTL covers (on 61 pages of new material!) most important aspects of Smart’s RTL libraries – graphics (HTML5 canvas), regular expressions, browser storage, accelerometer, touch and gesture, layout manager and networking (HttpRequest and JSONP). There was also a new section on running code on application shutdown added to the Programming with Smart chapter.

Click here for more information about the book …

A new poll is also available on the right side of the screen. Vote to tell me what is the next chapter of A Smart Book that I should be writing.

August 24, 2012

Application Shutdown

When you are writing a Smart application, you have to keep in mind that it's not a 'real' application but a web page running in a browser. As such, the user can at any time close the tab with your application or close a browser. The browser may also crash and the whole operating system hosting the browser that runs your application may die unexpectedly.

In short, there are many ways of terminating your application and you cannot be sure that you'll be notified when the application is being closed. You cannot always expect that your application will be given a signal before it is being closed. The best way to run a code on application shutdown is not to do it. [That is, restructure your code so it doesn't have to be run on application shutdown. Execute it before that.]

If you really want to run code on application shutdown, Smart offers you few ways to do it. You can override TForm.FinalizeObject or TApplication.ApplicationClosing. You can also write an event handler for TApplication.OnBeforeUnload and for TApplication.OnUnload, which roughly correspond to Delphi's OnCloseQuery and OnClose events. The only problem is that your application will not run on all major browsers correctly so you'll have to find a workaround for some browsers or just remove support for them.

To test the browser support for executing shutdown code, I have written a small program that logs various times during application startup and shutdown into cookie storage. Next time you start the application times from the previous run will be shown. Following points in the code are logged:

  • TApplication.ApplicationStarting
  • TForm.InitializeObject
  • TForm.FinalizeObject
  • TApplication.ApplicationClosing
  • TApplication.OnBeforeUnload
  • TApplication.OnUnload

As we could expect, the first two points which are executed while application is being started are always logged. Other four (called during the application shutdown) are correctly called only on some browsers.

Following browsers were tested:

  • Chrome 21.0
    Shutdown code is executed on first reload (F5) but not on subsequent ones. Shutdown code is not executed if tab or browser is closed.
  • Firefox 14.0.1
    Shutdown code is always executed.
  • Opera 12.01
    Shutdown code is never executed.
  • Safari 5.1.7 on Windows
    Shutdown code is always executed.
  • Smart 1.0.122 (internal browser)
    Shutdown code is always executed except that OnBeforeUnload is never called.
  • Safari on iOS 5.1
    Shutdown code is always executed except that OnBeforeUnload is never called.

Following two screens show results from Opera (left) and Safari on Windows (right).


July 16, 2012

Programming with Smart

A Smart Book has just been updated! In addition to one minor edit related to the recent Hotfix 2 release, I have included a whole new chapter about programming 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

The section on message dialogs is also available in the sample book.

Click here for more information about the book …

A new poll is also available on the right side of the screen. Vote to tell me what is the next chapter of A Smart Book that I should be writing.

July 05, 2012

New Poll

While I’m working on the “Introduction to OmniThreadLibrary” for my Parallel Programming with OmniThreadLibrary book, you can vote in the poll on the right to tell me what is the next chapter of A Smart Book that I should be writing.

Smart Controls

A Smart Book has a new chapter – Smart Controls.

On 54 pages, it 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 …

June 28, 2012

Smart Controls – Status Update

This is gonna be one long chapter …

Done: TW3TagValue, TW3Component, TW3MovableControl, TW3CustomControl, TW3GraphicControl, Panel, Label, Button, Checkbox, EditBox

To do: Memo, PaintBox, ComboBox, ListMenu, Toolbar, Toolbutton, Image, Header, TW3ScrollControl

June 23, 2012

A Smart Book – 1.0.1 Update

Smart Mobile Studio 1.0.1 has been released and I have updated existing material with new features – namely compiler support for Date/Time manipulation. I have also added documentation for Math and String internal functions.

Sample book has also been updated with this information so you can proceed to the Leanpub site and download the new version.

June 21, 2012

June 20, 2012

Smart Controls Chart

Chart of Smart Controls classes. Will be published in the Smart Book.


Solid lines indicate inheritance. Dashed lines indicate composition; circle indicates the owner. One-to-one relations are marked with a full circle and one-to-many relation. Classes with thicker red border represent visual components available in the designer.

June 18, 2012

Code Samples for the Book

Code samples for A Smart Book will be stored in the Google Code project a-smart-book.

First code samples for the Smart Controls chapter are already available.

June 16, 2012

Blogs to Watch [2]

If you are into database/remoting clients, written in Pascal and running in a browser, click through to AndrĂ© Mussche’s blog and Google+ page.

June 15, 2012

RemObjects Integration

Two weeks ago, Valeriy Goloshchapov of RemObjects published blog post RemObjects SDK for JavaScript and Smart Mobile Studio where he wrote:

“It’s quite easy to use RemObjects SDK for JavaScript as a third-party library with a quick asm section hack. The blog post of the Smart Mobile Studio creator shows that this may be done properly, and we’ll look into providing official and deeper integration with SmartStudio along those lines in the future.”

Today, Lennart Aasended announced in the Delphi developer Facebook group:

“Finally finished the RO import wizard. It does no longer need the codegen2.exe from RO SDK. So it's a 1 click affair to import a RODL service library :)”

Thanks to the hard work by André Mussche and Lennart, Smart may get RemObjects support in the first hotfix (due in a few days)!

June 08, 2012

Blogs to Watch [1]

If you would like to know more about solving basic tasks in Smart, bookmark Smart Mobile Studio – Basics and Beyond, written by Shane Holmes.

June 06, 2012

Where to Ask Questions about Smart

This blog may not be the right place to ask questions about the Smart Mobile Studio – unless they relate to a specific post, that is.

If you have a question about Smart, especially if it starts with “Why” or “When”, the best place to ask it is on the Smart Mobile Studio forum.

However, if you have a “How” programming question that could interest your fellow programmers, I’d suggest asking it on the Stack Overflow. The appropriate tag is called smart-mobile-studio.

June 03, 2012

A Smart Book – Current Status

imageIn accordance with the Lean Publishing Manifesto, A Smart Book is published as it is written. When I’m happy with a chapter (or even with a section, if it is important enough), I click the Publish button on the LeanPub site and new, updated book is available to all the readers.

Such a book would be of a little use if you would not be able do buy and read it before it is finished. Therefore, you can buy the book in the current state of completion and you’ll get all future versions for free. That way, you can get the information as soon as it is ready and I get feedback from my readers before the book is completed (which also means I can react immediately, fixing the errors and updating the already written parts). You’ll be informed by the email when an update is ready. Alternatively, you can follow this blog or my Twitter feed.

The picture on the right shows the structure of the book. Chapters marked green are already finished. Blue color marks the chapter I’m currently working on. Orange color indicates chapters that are available in the free sample book. Brown color marks the content that is only partially included in the sample book.

If you want to affect the order in which the book is written, go to the home page of this blog and vote in the current poll. The poll is restarted each time new part of the book is published.

To get a better idea about the way the book is written, check the sample PDF.

Code samples for the book are available in the a-smart-book Google Code project.

image image