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.
- The input is a Delphi DFM file saved in text mode.
- The output is a nicely formatted HTML code sent to file or rendered in a html browser at once.
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.
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
Form in design mode (Delphi IDE)
Form compiled (Delphi EXE)
Step 3: Create a php file similar to this below:
$t = new DelphiPHPForm('Unit1.dfm');
If everything went OK, you shall see form like below in your browser.
And the resulting html code (if you select "View Source") will look like this:
Form from PHP rendered in Mozilla Firefox (1.5)
Form from PHP rendered in Internet Explorer (6.0)
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.
To make DelphiPHPForm work correctly, you need to derive your form from 'TForm1' class
- this is default value of your form class, so if you start designing first form in Delphi IDE,
no class name change for form is required.
Due to the fact that Delphi stores picture data in DFM file and HTML takes it from outer file,
the solution chosen
in the code is to name TImage component as the picture file name witch full stop "." changed into
underline "_". I.e. picture name "test.jpg" would be transformed into "test_jpg" TImage name.
If the pictures are stored in different folder it can be set in $this->pic_folder property.
Usually DelphiPHPForm name the html form components like their counterparts in Delphi. The difference is
when dealing with radio buttons, which in Delphi have different names while in html shall be the same
to work together. So DelphiPHPForm names them like their container. It also resolves problem
with many radio buttons in different containers which should work independently. Of course all that
is done behind the scenes.
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
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).
If you find this class useful, funny, or requiring further maintaining, don't hesitate and contact me:
Feel invited to my personal homepage: glebowski.pl.
The project is currently hosted on Sourceforge. To download file please follow