Developer's Guide :: Hello World
From Delphi for PHP Documentation Wiki
The very first application you should want to create is a typical "Hello, world!" app, so here are the steps to get it done using pure PHP, you can get a more visual experience by using Delphi for PHP, but it's not required to use the framework.
<?php require_once("vcl/vcl.inc.php"); use_unit("forms.inc.php"); //Inherit from Page class MyPage extends Page { function buttonclick($sender, $params) { echo "Hello, world!"; } } //Create the page $page=new MyPage(); //Create the page and set some properties $button=new Button($page); $button->Name="button1"; $button->Caption="Click Here"; $button->Parent=$page; $button->Left=100; $button->Top=100; //Attach the event handler $button->OnClick="buttonclick"; //Make the page process the events $page->init(); //Show the page $page->show(); ?>
Let's go into the source code in more detail:
require_once("vcl/vcl.inc.php");
use_unit("forms.inc.php");
The first line includes the file vcl.inc.php, which is required to use the library, it provides the basic function use_unit(), which is used in the second line to include a unit that contains all the forms stuff.
The function use_unit is smart enough to find the right source code to include, always inside the VCL folder.
//Inherit from Page
class MyPage extends Page
{
function buttonclick($sender, $params)
{
echo "Hello, world!";
}
}
This block defines a new class that inherits from Page, which represents an HTML document and the function defined inside it's meant to be an event handler.
Event handlers should have two parameters, $sender and $params, the first one always contains the reference to the object that has called the event and $params can be anything, usually an array with extra info that you create.
//Create the page
$page=new MyPage();
//Create the page and set some properties
$button=new Button($page);
$button->Name="button1";
$button->Caption="Click Here";
$button->Parent=$page;
$button->Left=100;
$button->Top=100;
Now create an instance of your class, and also create a Button, setting $page as the owner of the button, so now the Button belongs to the page. After that, set some properties like the component name and the button caption and also the Parent property, which specifies into which component the button is going to be.
//Attach the event handler
$button->OnClick="buttonclick";
//Make the page process the events
$page->init();
//Show the page
$page->show();
The last block of code, assigns the OnClick event to the function we defined earlier and as you can see is a string, not a pointer, this gives more freedom writting dynamic code and also is used when create resource forms, we will see more on this on other pages.
The call to $page->init() makes all objects that belong to the form to call their events if they need to, and finally, call the show() method of the page to show the results of our code.
If you run that application, a button will be shown at the coordinates specified in your browser and when you click it, "Hello, world!" will be shown at the top left corner of your document.
If you are a Delphi for Win32/.NET, you will see that the code is very familiar, as the class library has been modeled after VCL for Windows.

