Can not compile the code with semi-OOP syntax.

Moderator: Rathinagiri

Post Reply
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

Can not compile the code with semi-OOP syntax.

Post 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
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

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

Post 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'
    ...
Viva INTERNATIONAL HMG :D
KDJ
Posts: 243
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland

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

Post by KDJ »

esgici

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