Web Development

Getting started with Delphi for PHP

Justin James guides you through a brief tour of CodeGear's Delphi for PHP, a visual IDE for developing applications in PHP. Find out what he thinks of the product.

 

After seeing the demo of CodeGear's Delphi for PHP product about a month ago, my initial impressions were that it was impressive. I recently got the chance to actually try out the product.

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.

Overview

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.

Welcome to Delphi for PHP

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.

As hinted at earlier, the page's HTML cannot be edited; in fact, the HTML does not exist at design time. Instead, there is an XML file (disguised as a PHP file) that contains all of the properties, references to event handlers, and everything else that is controlled through the Object Inspector. At run time, this file is parsed, and the actual HTML for the page is generated. I am not so sure if I like losing complete control of the HTML and entrusting an HTML generator with this task. On one hand, more and more "Web developers" either do not use or do not know HTML very well and rely upon tools like Eclipse and Visual Studio to generate the code for their page. On the other hand, every PHP developer I know considers writing HTML by hand part and parcel of their job, and I am not sure if those folks would willingly give up control of the HTML.

UPDATE on 9/19/2008: 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 feature 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.

J.Ja

Disclosure of Justin's industry affiliations: Justin James has a working arrangement with Microsoft to write an article for MSDN Magazine. He also has a contract with Spiceworks to write product buying guides.

-----------------------------------------------------------------------------------------------------------------

Get weekly development tips in your inbox Keep your developer skills sharp by signing up for TechRepublic's free Web Developer newsletter, delivered each Tuesday. Automatically subscribe today!

About

Justin James is the Lead Architect for Conigent.

6 comments
jomitech
jomitech

It is actually possible to write your own HTML code for the page. You can do this using the built-in Smarty template support, or via Template Pages.

BALTHOR
BALTHOR

Show us from start to finish how to write a virus scanning program.

Justin James
Justin James

Is this a tool that you think would make your job easier? J.Ja

Justin James
Justin James

Thank you for this information! That was not obvious at all using the software. I will be sure to update the article as well. J.Ja

Justin James
Justin James

Thank you for this information! That was not obvious at all using the software. I will be sure to update the article as well. J.Ja

Justin James
Justin James

Thank you for this information! That was not obvious at all using the software. I will be sure to update the article as well. J.Ja

Editor's Picks