Introduction of Delphi for PHP

Delphi for PHP is a visual IDE for developing applications in PHP. It is based on the same codebase as Delphi, and it implements a library of objects in PHP based on Delphi’s Visual Component Library (VCL). This will make working in Delphi for PHP a familiar experience to current or past Delphi or C++ Builder users. It also means that PHP developers have access to a full suite of pre-made, object-oriented controls for use in their applications.

Here’s a brief tour of Delphi for PHP, which I hope will help you bootstrap yourself into the environment. Because many regular readers are already familiar with Visual Studio, and because I am extremely familiar with it, I will be making many comparisons between Delphi for PHP and Visual Studio. Also, I won’t spend time discussing the PHP language itself, but I will show how the work in the IDE affects the PHP code underneath.

When you start Delphi for PHP, you’ll see a welcome screen that is similar to what you would see in Visual Studio (Figure A). There is a main window for code (which is initially occupied with links to open previous projects and files, news pieces, and so on), surrounded by toolboxes, project management windows, property viewers, and a code structure window, with a tabbed status/debugging window at the bottom.

Figure A

Figure A

When you start a new project, you will be asked what kind of project to start. For this example, I chose a new Application. This allows us to work with a completely blank slate project (Figure B). As you can see, the main work area is divided between a grid layout of the page and a source code view of the page. The toolboxes now contain information as well.

Figure B

Figure B

Getting down to business

Let’s take a closer look at the Object Inspector (which is used to edit the properties, events, and JavaScript of objects), where much of the action takes place (Figure C).

Figure C

Figure C
Again, this will look familiar to users of other IDEs. In this case, I will change the value of the Caption property from Unit1 to Test Page. As soon as I do, the <title> tag in the generated code is now changed to Test Page (Figure D) The reason for this is, the caption property was part of the page itself, so it maps to the <title> tag of the page.

Figure D

Figure D

It’s interesting that the code displayed is generated directly from the object’s properties and cannot be modified. While this may frustrate many users, the reasoning behind it is to eliminate odd discrepancies between the user’s handmade changes and changes made in the IDE.

As expected, you can drag and drop controls from the toolbox (called the Tool Palette) onto our page. In this example, I will place a text box and a button on the page. I can select the controls on the page with the mouse and use the Object Inspector to modify the associated properties, events, and JavaScript. The difference between Events and JavaScript is that Events handles things that occur server-side and JavaScript items are run on the client side. The OnClick event of a button, for example, is run on the server when a postback occurs as a result of clicking the button. So an object with JavaScript for OnClick and an event handler for OnClick would run the JavaScript, perform the page postback, and then run the event handler code on the server. Double clicking an object in the designer will take you to that object’s default event handler and create an empty event handler if you have not already made one.

Making it look good

The final piece of the puzzle is to make the page look good. To do that, I will attach a stylesheet by first creating a style sheet and adding it to the project. From the File menu, choose New, choose Other in the resulting dialog box, select CSS in the tree on the left, and then click OK. If you have an existing stylesheet that you would like to add to the project, you can do so through the Project menu.

Once you add the stylesheet to the project, it is easy (but not obvious) to add it to the page. In the Tool Palette, you scroll down to the System group, select the StyleSheet control, and drop it onto the page. After the stylesheet is added to the page, you can select it and change the FileName property of the control in the Object Inspector to the name of your stylesheet. Once it is added, you will see that the Style property of the controls on your page has a drop-down list populated with the styles in the stylesheet. You will note that the Style property will not include any styles that do not apply to that type of control.

The code model

Delphi for PHP formalizes the potential “division of labor” between the presentation and the business logic. In PHP, it is possible to put all of the processing code embedded into the HTML code. But a good number of PHP developers choose to separate their code, putting all of the logic in a separate file and then including it in the file that is officially the page. In Delphi for PHP, there is a complete and formal separation between the code used for the presentation, and the code used for the logic.

A feature that I overlooked while writing this, is that it is possible for the developer to create their own templates for the system, which in turn gives them control over the HTML. This features was not intuitively obvious when using the product and the documentation did not mention it in this context. If you require control over the HTML, you can have it, but it will require some additional effort on your part.

The big picture

The relative lack of kludge that pervades systems such as ASP.NET and J2EE leads to Delphi for PHP being much less complex in operation and development, which is then reflected in the IDE itself. However, Delphi for PHP may seem too simplistic for many experienced ASP.NET and J2EE developers. I think that many current PHP developers may feel constrained by it, since they have come to expect the full control over HTML that other tools provide them. ASP.NET developers are used to giving up this control to various widgets. The best thing to do is to give the Delphi for PHP free trial a spin, and see if the product is for you.

Courtesy: Techrepublic : Justin James

Shout me your experiences with Codegear’s Delphi for PHP. If you like this post kindly subscribe to our RSS for free updates and articles delivered to you.

0 I like it
0 I don't like it