WinDDE example

This section provides a WinDDE example.

dde_example.per
DATABASE formonly
SCREEN
{
Value to be given to top-left corner :
[f00                                ]
Value found on top-left corner :
[f01                                ]
}
ATTRIBUTES
  f00 = formonly.val;
  f01 = formonly.rval, NOENTRY;
dde_example.4gl
MAIN
  -- Excel must be open beforehand
  CONSTANT file = "Sheet1"
  CONSTANT prog = "EXCEL"
  DEFINE val, rval STRING
  DEFINE res INTEGER
  OPEN WINDOW w1 AT 1,1 WITH FORM "dde_example.per"
  INPUT BY NAME val
  CALL ui.Interface.frontCall("WINDDE","DDEConnect", [prog,file], [res] )
  CALL checkError(res)
  CALL ui.Interface.frontCall("WINDDE","DDEPoke", [prog,file,"R1C1",val], [res] );
  CALL checkError(res)
  CALL ui.Interface.frontCall("WINDDE","DDEPeek", [prog,file,"R1C1"], [res,rval] );
  CALL checkError(res)
  DISPLAY BY NAME rval
  INPUT BY NAME val WITHOUT DEFAULTS
  CALL ui.Interface.frontCall("WINDDE","DDEExecute", [prog,file,"[save]"], [res] );
  CALL checkError(res)
  CALL ui.Interface.frontCall("WINDDE","DDEFinish", [prog,file], [res] );
  CALL checkError(res)
  CALL ui.Interface.frontCall("WINDDE","DDEFinishAll", [], [res] );
  CALL checkError(res)
  CLOSE WINDOW w1
END MAIN

FUNCTION checkError(res)
  DEFINE res INTEGER
  DEFINE mess STRING
  IF res THEN RETURN END IF
  DISPLAY "DDE Error:"
  CALL ui.Interface.frontCall("WINDDE","DDEError",[],[mess]);
  DISPLAY mess
  CALL ui.Interface.frontCall("WINDDE","DDEFinishAll", [], [res] );
  DISPLAY "Exit with DDE Error."
  EXIT PROGRAM (-1)
END FUNCTION