Page 1 of 1

window setfocus problem

Posted: Tue Oct 16, 2012 6:41 am
by apichit
Hi All,

I don't understand why code " form1.setfocus" not work in PROC1 but works in PROC3.

Apichit

Code: Select all

#include <hmg.ch>

Function Main

   DEFINE WINDOW WinMain ;
      AT 0,0 ;
      WIDTH 640 ;
      HEIGHT 460 ;
      TITLE "Move child window over another chile window" ;
      ICON "InvoiceIcon" ;
      MAIN   ;
      backcolor {0, 128, 192};
        
      @ 176,320 BUTTON cmdForm1 ;
         CAPTION '&Form1' ;
         ACTION proc1() ;
         BOLD

      @ 204,320 BUTTON cmdForm2 ;
         CAPTION 'Form2' ;
         ACTION proc2() ;
         BOLD

      @ 232,320 BUTTON cmdForm1Top ;
         CAPTION 'Form1 on Top' ;
         ACTION proc3() ;
         BOLD
         
   END WINDOW

   *Maximize window winMain
   Center window winMain
   ACTIVATE WINDOW WinMain

Return

static proc proc1
   if isWindowDefined(form1)
      form1.setfocus             // This line give an error at complie time
      return nil
   endif

   define window form1 ;
      at 114,218 ;
      width 334 ;
      height 276 ;
      child ;
      title 'form1' 
      
   end window
   form1.activate
   RETURN

static proc proc2
   define window form2 ;
      at 214,188 ;
      width 334 ;
      height 276 ;
      child ;
      title 'form2' 
      
   end window
   form2.activate
   RETURN
   
static proc proc3
   form1.setfocus                       // This line works well at compile and rum time
   RETURN

Re: window setfocus problem

Posted: Tue Oct 16, 2012 7:13 am
by mol
It's because proc1 is declared before definition of form1.
You can use phrase:

Code: Select all

declare window form1
placed on the top of code and everything should be OK.

Marek

Re: window setfocus problem

Posted: Tue Oct 16, 2012 7:42 am
by apichit
Can I declare 2 windows in one line like this:

declare window Form1, Form2

Thank you very much Marek. :D
Apichit

Re: window setfocus problem

Posted: Tue Oct 16, 2012 10:35 am
by mol
You can declare all forms acrross all modules you're using.
I don't remember if forms can be listed after the comma, or every form should be declared in single line...

Re: window setfocus problem

Posted: Thu Nov 22, 2012 8:45 am
by gybartal
or the use :

DoMethod ( "form1", "setfocus" )

Gyula