VCL for PHP Charting components - Initial setup

Posted by on in Blogs
On the previous article, we learned how to gather the requeriments to write the wrapper, now we are going to setup the folder where to place our component files and write some code.

Components folder


Our component must live on the VCL for PHP folder the IDE uses, which, by default, is C:\Program Files\CodeGear\Delphi for PHP\2.0\vcl, so let's create a subfolder called openchart inside.

Now we need to identify the open flash chart library files we need to include, to make all work, I usually copy everything, including samples and documentation, that way, you are respecting the package the author deployed, and also is easier to upgrade in the future.

In this case, we include everything, except the non-PHP APIs, so this should be the content of the vcl\openchart folder:


Component and package


A component is a class that inherits from a VCL for PHP base class, and to allow the IDE to use it, you need to create a package, which tells the IDE where to place the component icon on the Tool Palette, and also how to handle some of its properties.

To create the basic code for the component and the package, we are going to use the New Component Wizard, you can find it on Component | New Component menu item.

You need to enter some information, like the ancestor class, the name for your new component and the palette page you want to place your new component on.



After pressing OK, you will end up with two files:

unit1.inc.php
<?php
require_once("vcl/vcl.inc.php");
//Includes

//Class definition
class OpenChart extends Control
{
function __construct($aowner = null)
{
parent::__construct($aowner);
}

function dumpContents()
{
parent::dumpContents();
}
}

?>

unit1.package.php
<?php
require_once("vcl/vcl.inc.php");
use_unit("designide.inc.php");

setPackageTitle("Put the title of your package here");
//Change this setting to the path where the icons for the components reside
setIconPath("./icons");

//Change yourunit.inc.php to the php file which contains the component code
registerComponents("OpenChart",array("OpenChart"),"unit1.inc.php");
?>

Save both on the vcl\openchart folder and name them openchart.inc.php and openchart.package.php.

Customizing and installing the package


Before installing the package, you must perform some customizations, like change the title of the package:
setPackageTitle("Charting Library for VCL for PHP");

Or change the path where the unit for the component is located:
registerComponents("OpenChart",array("OpenChart"),"openchart/openchart.inc.php");

You can also specify where the component icons can be found by the IDE These icons will be used by the IDE on the Tool Palette to represent a component.
setIconPath("./icons");

All the information contained in a package is information for the IDE, so you don't need to deploy .package files with your application.

Finally, you need to add the unit where the Control base class can be located, which is controls.inc.php:
require_once("vcl/vcl.inc.php");
//Includes
use_unit("controls.inc.php");

Now you are ready to install your package into the IDE, using Component | Packages, click the Add button and browse where openchart.package.php is located and open it. The package will be installed and the component will be available on the Tool Palette, under the OpenChart category.

If you drop your new component to a Page, you will get a blank rectangle with nothing, that is the basic component, and we will add functionality on the next article.


Comments

  • Guest
    Orlando Lopez Monday, 22 December 2008

    Muy bueno Jose, pero cuando crearas el blog para agregarle funcionalidad al componente creado, estoy esperando dicho blog y espero que sea pronto, gracias y buen aporte

  • Guest
    halat Monday, 26 January 2009

    hi .thanks for delphi for php .is best lang for programing

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: