logo

DelphiPHPForm is a small and simple Delphi DFM form interpreter written in PHP.

The main goal of the DelphiPHPForm class is to enable designing HTML forms using popular Delphi design interface. The user designs a form in a Delphi IDE, then he saves it in a DFM format (save as text option!), and then PHP class can render this form on a web page as if it was created in plain html.

DelphiPHPForm class recognizes and renders following Delphi VCL components:



Since there is multitude of VCL components in Delphi, the above class interprets only small amount of them. Only components which are easily transformable to HTML were used. The following properties are recognized and adequately handled:

Working with the class - step by step

Step 1: Design form using Delphi IDE GUI designing facilities. Here I created the form which code you can get here.
Form in design mode (Delphi IDE)

Form in design mode (Delphi IDE)

Form compiled (Delphi EXE)

Form compiled (Delphi EXE)

Step 2: If you design your form yourself, remember to save it as text. To do it place the mouse pointer over the form, press second mouse button and select option Text DFM. When you similarly select option View as Text you'll get the code like in the box below. So you can see that it is a kind of hierarchical code. Below the outlook of rendered forms in html are presented. The html almost perfectly mimics the Delphi layout. It is worth mentioning that such look did not require much effort.
Step 3: Create a php file similar to this below:
<html>
  <body>
<?php
  require_once('DelphiPHPForm.php');
  $t = new DelphiPHPForm('Unit1.dfm');
  $t->draw_dfm();
?>
  </body>
</html>
If everything went OK, you shall see form like below in your browser.
Form from PHP rendered in Mozilla Firefox (1.5)

Form from PHP rendered in Mozilla Firefox (1.5)

Form from PHP rendered in Internet Explorer (6.0)

Form from PHP rendered in Internet Explorer (6.0)

And the resulting html code (if you select "View Source") will look like this:

Rendering rules

Usually Delphi properties have their counterparts in html code. At least some of them. The DFM file has some kind of tree structure. It means that some components are placed inside others (containers), the containers here are: TForm and TPanel. The rest of the components rendered cannot hold other components in themselves.
TPanel and TForm components are compiled by PHP class as <div>s. And components placed in them are positioned relativelly to their position (as in Delphi - internal comoponents of TPanel or TForm are positioned to their top/left corners). This positioning rule allowed to transfer positions data of components without need of recalculating.

Designing rules

History

This is so called 'one day' project, because the first version (0.9) took me one day to create. As I am a Delphi programmer, through the years I found it's GUI designing facilities very convenient and appealing. I was wondering if similar functionality would be achieved with HTML form encoding. So I wrote this small (now it has about 300 lines of code) class, and even added some kind of form header to mimic it's delphi brother. The results are quite promising however I did not tested the code on the other browsers than Mozilla Firefox 1.5 and Internet Explorer 6.0.

Delphi? what is it?

If you do not know what Delphi is, the above class is probably not for you. Delphi is a programming language (based on the Object Pascal) which besides the compiler is equipped with very intuitive IDE with GUI design facility. Although Delphi software is not a GPL licensed nor it is freeware, it has some free versions which can be downloaded from Borland site (http://www.borland.com/downloads/download_delphi.html). However for now there are no free full version on that site, many versions of Delphi have been issued in IT magazines (I personally owe Delphi 2005 Personal from magazine).

Contact

SourceForge.net Logo Valid XHTML 1.0 Transitional If you find this class useful, funny, or requiring further maintaining, don't hesitate and contact me: glebows@chemeng.p.lodz.pl.
Feel invited to my personal homepage: glebowski.pl.

Download

The project is currently hosted on Sourceforge. To download file please follow project page.