window setfocus problem

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
apichit
Posts: 33
Joined: Thu Jun 07, 2012 9:39 am

window setfocus problem

Post 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
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: window setfocus problem

Post 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
apichit
Posts: 33
Joined: Thu Jun 07, 2012 9:39 am

Re: window setfocus problem

Post by apichit »

Can I declare 2 windows in one line like this:

declare window Form1, Form2

Thank you very much Marek. :D
Apichit
User avatar
mol
Posts: 3825
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: window setfocus problem

Post 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...
gybartal
Posts: 1
Joined: Wed Nov 21, 2012 9:06 pm

Re: window setfocus problem

Post by gybartal »

or the use :

DoMethod ( "form1", "setfocus" )

Gyula
Post Reply