-1

The project runs fine on my development machine. But on the webserver, one of the pages gets its oncreate fire up about 50 times and then a button gets pressed automatically. That was my first impression. But I realise now that something is just caching the last state of the form (and its not the browser as it doesnt happen locally and I have cleared its cache).

How can I prevent this ?

<?php
require_once("vcl/vcl.inc.php");
use_unit("forms.inc.php");
use_unit("stdctrls.inc.php");
use_unit("comctrls.inc.php");

//Class definition
class frm_Sign_Up extends Page
{
   public $lbl = null;
   public $cbx = null;
   public $lblHdr = null;
   public $btnSignUp = null;
   public $btnCancel = null;


   function frm_Sign_UpCreate($sender, $params)
   {
     // Populate Combobox
     $this->Populate();
   }

   function Populate()
   {
     // Count number of times Create is run
     $this->cbx->AddItem($this->cbx->Count);
   }

   function btnSignUpClick($sender, $params)
   {
      // Display it
      $Error = 'x';
      if ($Error <> '')
      {
        $this->lbl->Caption = 'Pressed '.$this->cbx->Count;
        $this->lbl->Visible = true;
        return (false);
      }
      else
      {
        redirect ('app_main.php');
        exit;
      }
   }
}

global $application;

global $frm_Sign_Up;

//Creates the form
$frm_Sign_Up=new frm_Sign_Up($application);

//Read from resource file
$frm_Sign_Up->loadResource(__FILE__);

//Shows the form
$frm_Sign_Up->show();
?>
Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • 7
    It's definitely line 523 in `flargarble.foo`, there's a dot missing. Seriously though, please give us *some* information to work with. – deceze Mar 11 '11 at 10:13
  • @Rohit Gupta, what steps did you take to debug this? How do you know the oncreate fires about 50 times? – Cosmin Prund Mar 11 '11 at 10:24
  • I tried to post the source for the form, but its too big. function frm_Sign_UpCreate($sender, $params) { Connect_To_Database ($this->dbs); // Populate Countries, Cities are populated on change event $this->Populate_Countries(); } Populate_Countries adds a static item 'Please Select' and that gets added about 50 times. – Rohit Gupta Mar 11 '11 at 10:35
  • 4
    Then try some debugging and narrow it down to some specific piece of code. If code is too big to post here, nobody's going to go through it for you anyway. And please add any code to your question, formatted as code. Comments are no good for posting code. – deceze Mar 11 '11 at 10:38
  • It appears that every time the form is refreshed, it executes the oncreate event but all variables retain their values. This is counter-intuitive to me. Is there a standard way that others get around this issue ? And why does it not happen on my development pc ? – Rohit Gupta Mar 11 '11 at 10:54
  • 2
    As I said, barely anybody will go through this for you. At least I know I won't. Please try to narrow it down yourself a bit first. Debugging is a valuable skill to learn. – deceze Mar 11 '11 at 11:07
  • 3
    Debug tips: Start shaving off code from the page. Remove some fields, remove all associated code. When the bad behavior stops you know you just removed the bad code. If you keep removing and you end up with just a blank page with it's create event and it still gets called 50 times, post that and ask for directions. But as deceze said, nobody's going to go throw that amount of code for you! – Cosmin Prund Mar 11 '11 at 11:11
  • I realise now that something is just caching the last state of the form (and its not the browser as it doesnt happen locally and I have cleared its cache). I have simplified the form code above. How can I prevent this ? – Rohit Gupta Mar 11 '11 at 20:01
  • I have added teh following to the page so it no longer appears that the button has been pressed. But the cbx still has a lot of values – Rohit Gupta Mar 11 '11 at 20:15
  • header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" ); header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); header( "Cache-Control: no-cache, must-revalidate" ); header( "Pragma: no-cache" ); – Rohit Gupta Mar 11 '11 at 20:15

1 Answers1

2

Very few people know the Delphi for PHP framework, and those that do know it don't seem to hang out here. There's nothing in the code you've posted that would present the symptoms you've described.

But you aren't out of luck, my friend! Install xdebug on the server. It will allow you to use any industry standard debugging tool to step through the entire codebase as it handles things. You'll be able to stop the code mid-execution, inspect variables, skip blocks, and perform other critical debugging steps.

Using this, you will be able to locate the code or condition that is causing the function to be called an excessive number of times.

Charles
  • 50,943
  • 13
  • 104
  • 142
  • -1. Might almost be useful if it weren't for the rant about the language/IDE. Edit that out and I'll reconsider my downvote. – Ken White Mar 11 '11 at 20:48
  • Eh, it was a preamble trying to explain the lack of answers so far. Unpopular simply means unpopular, it was not intended as an attack on the IDE or toolkit. I've never used it an am unable to express that type of opinion on it. (Okay, maybe I was mocking the rename...) – Charles Mar 11 '11 at 20:51
  • @Charles, you apparently edited in the 5 minute window; the fact you edited the post isn't indicated, and SO won't let me revert my vote. Please edit it again so I can do so? – Ken White Mar 11 '11 at 21:27
  • @Ken White, I've added a few words. It should show as edited for you now. Thanks for the reconsideration! – Charles Mar 11 '11 at 21:31
  • @Charles, thanks for the reply. I did not take it as an attack on the IDE. I would not recommend that anyone use it anyway. Its Borland/Codegear's poorest effort in 25 years that I have been using their products. It just appears that for whatever reason the form is dislayed a number of times when its from the server. So, I have simply modified the code to cope with it. – Rohit Gupta Mar 13 '11 at 11:54
  • Final unsolved problem. My ajax callback used to work. In an effort to fix the above problem, it has stopped working. Again, I am confident that there is nothing in my code. That part is identical to when it used to work. Its just the delphi-4-php or php itself being iffy. Tracing thorugh, the callback does happen and the combobox does get populated with values - the user just doesnt see it until any button is pressed on the form. – Rohit Gupta Mar 13 '11 at 12:00