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!
  8. And by that I mean 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 http://17slon.com/blogs/gabr/BPM/FourWaysToCreateAThread.zip.

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.
                                            
--Anonymous

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.