The first Delphi for PHP applet

Source: Internet
Author: User
Tags class definition php code rand

Today it took one hours to write a small program, my Delphi PHP's first program. The function is to display a simple addition problem in the browser, the user can input the answer, the computer will tell you right or wrong, and then you can have another question. function is very simple, mainly in order to familiarize yourself with Delphi for PHP, when writing, check out PHP help, find this codegear PHP help is still good.

The procedure is as follows:

//includes
require_once ("vcl/vcl.inc.php");
Use_unit ("forms.inc.php");
Use_unit ("extctrls.inc.php");
Use_unit ("stdctrls.inc.php");
//class definition
Class Unit3 extends Page
{
Public $txtAnswer = null;
public $btnB = null;
Public $btnA = null;
Public $btnRun = null;
Public $lblMsg = null;
Public $Button 4 = null;
Public $Button 2 = null;
Function Btnrunclick ($sender, $params)
{
$a =rand (1,9);
$b =rand (1,9);
$this->btna->caption= $a;
$this->btnb->caption= $b;
$this->lblmsg->caption= "";
$this->txtanswer->text= "";
}
Function Txtanswersubmit ($sender, $params)
{
Global $a;
Global $b;
Global $c 0;
Global $c 1;
$a = $this->btna->caption;
$b = $this->btnb->caption;
$c 0= $a + $b;
$c 1= $this->txtanswer->text;
if ($c 0== $c 1) {$this->lblmsg->caption= "right";
} else {$this->lblmsg->caption= "wrong";
}
}
}
global $application;
Global $Unit 3;
//creates the form
$Unit 3=new Unit3 ($application);
Read from resource file
$Unit 3->loadresource (__file__);
Shows the form
$Unit 3->show ();
? "

The first time you write PHP has the following feelings:

The 1 delphi4php IDE is strong, fast, and with powerful weapons such as vcl4php, other Ides such as Zend can be completely forgotten. The fluent feeling of Delphi's IDE is only vs can be compared.

2 $this->lblmsg This kind of object writing, come up always not adapt, because not how to read PHP5 book, later saw a few examples, basically understand. In fact, and Delphi original object-oriented system is almost the same, but only the syntax is different, because the code prompts the speed is very fast, so if there is no code hint, you can think that is written wrong.

3 Write $this very wordy, do not know if there is no way to simplify.

4 because it is object-oriented, you only need to consider the event processing, the above code only two internal function of the code is written, the other is Delphi automatically generated.

5 above the program has a small error, that is, when the again button clicked, in the empty text is worth the time, will send a submit, resulting in label display wrong information. I think you can use a variable that represents a state for global control.

6 Every sentence is to be used; End, especially in the IF statement, this is somewhat different from Pascal.

The 7 powerful IDE can determine the level of {} without error.

8 Feel This example is almost the same as the Windows native program. And it's a lot simpler than intraweb. PHP in the end is very strong Ah, Delphi is stronger.

9 The PHP code generated by the wizard will not work properly on DH and surpass. DH error message seems to be not supported inc.php such a suffix, because I can not modify DH installed PHP settings file, had to have the opportunity to build an Apache service up to test. delphi4php oneself in debugging time use is Apache, I think should be the problem of setting up.

10 It is said that delphi4php is not good for Chinese support and has not been tested.

11 It is not convenient to check the correct syntax function without shortcut keys.

Slowly continue to study.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.