Problem in PHP-GTK application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vishal Jayaswal

    #1

    Problem in PHP-GTK application

    Hi,
    I m vishal jayaswal. I m doing my BE from Agra and i m working on PHP.
    At present i m creating an small application for adding two numbers.
    Enter forst number in one text box and second number in other text
    box. When you click the button Result, sum of both the number thta are
    entered in both the text boxes, shown in result text box. but this
    code create an error when i run this code:

    <?
    if (!class_exists( 'gtk'))
    {
    if (strtoupper(sub str(PHP_OS, 0, 3)) == 'WIN')
    dl('php_gtk.dll ');
    else
    dl('php_gtk.so' );
    }
    function delete_event()
    {
    return false;
    }
    function destroy()
    {
    Gtk::main_quit( );
    }
    function result($button, $window)
    {
    $gettext1 = $ent1->get_text();
    $gettext2 = $ent2->get_text();
    $result = $gettext1 + $gettext2;
    $ent3->set_text($resu lt);
    }
    function test1()
    {
    global $window;
    global $ent1;
    global $ent2;
    global $ent3;
    $window->destroy();
    }
    $window = &new GtkWindow();
    $window->set_name('Ma in Window');
    $window->set_title('Int roduction to PHP-GTK');
    $window->connect('destr oy', 'destroy');
    $window->connect('delet e_event', 'delete_event') ;
    $window->set_border_wid th(5);
    $window->set_position(G TK_WIN_POS_CENT ER);
    $frame = &new GtkFrame('Calcu lator');
    $window->add($frame);
    $table = &new GtkTable(3, 2, false);
    $frame->add($table);
    $num1 = &new GtkLabel('Numbe r1: ');
    $num2 = &new GtkLabel('Numbe r2: ');
    $ent1 = &new GtkEntry();
    $ent2 = &new GtkEntry();
    $ent3 = &new GtkEntry();
    $button = &new GtkButton('Resu lt');
    $button->connect('click ed', 'result', '$window');
    $table->attach($num1,0 ,1,0,1);
    $table->attach($num2,0 ,1,1,2);
    $table->attach($button ,0,1,2,3);
    $table->attach($ent1,1 ,2,0,1);
    $table->attach($ent2,1 ,2,1,2);
    $table->attach($ent3,1 ,2,2,3);
    $window->show_all();
    Gtk::main();
    ?>

    Error Occured:

    C:\php4>php c:\php4\test\te st1.php
    Fatal error: Call to a member function on a non-object in
    c:\php4\test\te st1.php
    on line 23

    Please send me the solution of this problem.
  • roberto

    #2
    Re: Problem in PHP-GTK application

    billoo_billoo@y ahoo.com (Vishal Jayaswal) wrote in
    news:bad7eb12.0 309042142.7d35c 24@posting.goog le.com:
    [color=blue]
    > Hi,
    > I m vishal jayaswal. I m doing my BE from Agra and i m working on PHP.
    > At present i m creating an small application for adding two numbers.
    > Enter forst number in one text box and second number in other text
    > box. When you click the button Result, sum of both the number thta are
    > entered in both the text boxes, shown in result text box. but this
    > code create an error when i run this code:
    >
    > <?
    > if (!class_exists( 'gtk'))
    > ...[/color]

    The problem is function 'result'.

    In this function the global declarations of '$ent1', '$ent2', '$ent2' are
    not present.

    This is the correct version:

    function result($button, $window)
    {
    global $ent1;
    global $ent2;
    global $ent3;
    $gettext1 = $ent1->get_text();
    $gettext2 = $ent2->get_text();
    $result = $gettext1 + $gettext2;
    $ent3->set_text($resu lt);
    }

    -------------------------
    Roberto
    Dedicato alla programmazione in Delphi, Visual Basic, AutoLISP, PHP, contiene solo materiale gratuito. Librerie, codice sorgente, programmi di utilità, trucchi, libri, link, tutto completamente gratuito. Only Free and Open Source !!


    Comment

    Working...