今天花了一个小时写了一个小程序,我的delphi php的第一个程序。功能是在浏览器上显示一道简单的加法题,用户可以输入答案,电脑会告诉你正确或者错误,然后可以再来一题。功能很简单,主要为了熟悉delphi for php,写的时候,不时地查阅php帮助,发现这次codegear的php帮助做的还是不错的。
程序如下:
//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 $Button4 = null; public $Button2 = 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 $c0; global $c1; $a=$this->btnA->Caption; $b=$this->btnB->Caption; $c0=$a+$b; $c1=$this->txtAnswer->Text; if ($c0==$c1){$this->lblMsg->Caption=”Right”; } else {$this->lblMsg->Caption=”Wrong”; } } } global $application; global $Unit3; //Creates the form $Unit3=new Unit3($application); //Read from resource file $Unit3->loadResource(__FILE__); //Shows the form $Unit3->show(); ?>
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved 京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089