Page 1 of 1

Can not compile the code with semi-OOP syntax.

Posted: Mon Sep 12, 2016 9:02 pm
by KDJ
This code can not compile -> Syntax error at line 39 (WindowChild.SETFOCUS):

Code: Select all

#include 'hmg.ch'

FUNCTION Main()

  DEFINE WINDOW WindowMain;
    MAIN;
    ROW    100;
    COL    200;
    WIDTH  340;
    HEIGHT 100;
    TITLE  'Main window'

    DEFINE BUTTON Child_BU
      ROW      20
      COL      10
      WIDTH   150
      HEIGHT   25
      CAPTION 'Create child window'
      ACTION  CreateChild()
    END BUTTON

    DEFINE BUTTON Exit_BU
      ROW      20
      COL     170
      WIDTH   150
      HEIGHT   25
      CAPTION 'Exit'
      ACTION  WindowMain.RELEASE
    END BUTTON
  END WINDOW

  WindowMain.ACTIVATE

RETURN NIL

FUNCTION CreateChild()

  IF IsWindowDefined(WindowChild)
    WindowChild.SETFOCUS
    //DoMethod('WindowChild', 'SETFOCUS')
    RETURN NIL
  ENDIF

  DEFINE WINDOW WindowChild;
    CHILD;
    ROW    180;
    COL    220;
    WIDTH  180;
    HEIGHT 100;
    TITLE  'Child window';
    NOSIZE

    DEFINE BUTTON Close_BU
      ROW      20
      COL      10
      WIDTH   150
      HEIGHT   25
      CAPTION 'Close'
      ACTION  WindowChild.RELEASE
    END BUTTON
  END WINDOW

  WindowChild.ACTIVATE

RETURN NIL

Re: Can not compile the code with semi-OOP syntax.

Posted: Mon Sep 12, 2016 9:38 pm
by esgici
KDJ wrote:This code can not compile -> Syntax error at line 39 (WindowChild.SETFOCUS):
HMG reference wrote: DECLARE WINDOW
Declares a Window Name

DECLARE WINDOW <WindowName>


A window must be declared using this command, if you need to refer to it prior its definition in code, or when you refer to it in a different .prg file from the one it was defined using semi-oop syntax.
So you need simply add "DECLARE WINDOW" command at top of your "MAIN" prg:

Code: Select all

#include 'hmg.ch'

DECLARE WINDOW WindowChild  // <===

FUNCTION Main()

  DEFINE WINDOW WindowMain;
    MAIN;
    ROW    100;
    COL    200;
    WIDTH  340;
    HEIGHT 100;
    TITLE  'Main window'
    ...

Re: Can not compile the code with semi-OOP syntax.

Posted: Tue Sep 13, 2016 5:58 pm
by KDJ
esgici

Oh yes, thanks for reminding me.
I've read the documentation but completely forgot about "DECLARE WINDOW".