Saturday, March 31, 2007

D4PHP a first impressions review

As a non PHP programmer, let's say a PHP rookie, I was excited that Delphi for PHP hit the doorstep this week. I always wanted to use/learn PHP but for several reasons that had not happen, until now. Delphi for PHP seems to be a very good start point for learning PHP as a Delphi programmer.

Installation
Installation gave, as expected, no problems. The installation is a little different to Delphi 2007 for Win32 which we now might consider the sister or brother of Delphi for PHP.

Using Delphi for PHP
After starting Delphi for PHP you will feel right at home because the IDE is almost similar to Delphi 2007. It is all there, the Code Explorer, the Object Inspector, the Project Manager and the Toolpalette. Also the welcome page is present.
The look and feel is the same, however the working of some elements are slightly different compared to Delphi 2007. (For example Code Insight and debugging 'feel' different)
Delphi for PHP comes with a lot of samples. The sample projects are located on a, not that, obvious location namely "C:\Program Files\CodeGear\Delphi for PHP\1.0\VCL\Samples". After some searching I found this link via the "Sample and Demos" link on the Welcome page.

The componentset, offered on the Tool Palette, is amazingly similar to the Delphi 2007 standard set. You will recognize lots of components, from Button and Edit, to Actionlist and PageControl. Also the Database control, like DataSource, Table and Query are available.
This really gives Delphi programmers a headstart!

My first PHP webapplication
OK, time to build my first PHP application.
Armed with my free PHP 5.0 power programming book I started some basic coding. PHP syntax is similar to C syntax, but that is another story. Using the VCL and its controls is a known experience:
Drop a Listbox, drop an Edit and a Button, double click the button and the ButtonClick event appears in the code just as in Delphi. The IDE is a little slow on drawing the controls on the design interface, but it is not disturbing me.
Debugging the code is easy although it does not show parameter values in a hint when placing your mouse on it. I suppose this will be improved in later versions.

Where is the HTML?
Using ASP.NET HTML is immediately generated on the design page. In Delphi for PHP you will not find any HTML (at least I did not find it yet, is it there?).
At first it is a bit strange and scary that there is no HTML (we are building a website, aren't we?) and gives you the feeling that D4PHP is mainly for pure application type websites instead of fancy HTML websites.
But D4PHP offers a template model for HTML files which can be used to "inject" your PHP components and code into HTML.
Big difference to ASP.NET, but I think I may like this. It seems to divide code and layout even more then ASP.NET. (First impression, have to investigate this much more)
Nice side effect here is that the IDE can't mess around with the HTML which happens a lot when you use ASP.NET IDE's like Delphi or Visual Studio.

There is a nice template demo in the sample projects which shows this technology.
A HTML page with D4PHP injected PHP looks like this:

{$lbMessage} is a label on your PHP page, just as {$RichEdit1} and {$btnSendContens}. On your page you code the button click, in this case the text of the RichEdit control is placed into the label lbMessage.

When the application runs the PHP controls are injected into the template and code runs just normal.

Looks pretty flexible to me.

Using databases
D4PHP offers a, almost endless, list of possible database connections. Two of them, MySQL and Interbase, are supported by the Data Explorer, and can be used to drag-and-drop database connections, tables and fields.
I tried to setup a connection to an Access database which I happen to use for my website, but I have not yet been able to get it to work.
HELP (F1)?
Press F1 and help is executed immediately. The Help however is a bit dissapointing. It is context sensitive and finds the right property, but gives information like this:

This is getConnected, a member of class Database

Well we knew that, didn't we? We would like to have information on how to use it!
A good alternative is the sourceforge help which seems to give more information.

Conclusion
Delphi for PHP is a real member of the Delphi family. The IDE and VCL will be very familiar to Delphi programmers. Coding in D4PHP is like coding in Delphi, quick, clean and easy.
Its alternate approach (I compare this to ASP.NET) is refreshing and the more I think about it the more I like it! Using Templates with PHP injection seems to be a very flexible and clean solution.
The help and documentation is not good and needs huge improvement.
Considering that it is a 1.0 product I think it is a great piece of work. It inspires me to dive into PHP 'the Delphi way'.


2 comments:

Stuart Kelly said...

Have a look at the dumpContents funtions in the source. Here is where the page HTML output starts.

Cheers, Stu

Imam ferianto said...

on my side, D4PHP is very slow when displaying data with many rows and paging not works correctly with mysql5 (always show first page) maybe the code behind vcl dbgrid is using ARRAY and NoT optimized yet with paging query command: SELECT * FROM TABLEX LIMIT pagex,nrows .
Not recomended for production use!