Code will not run without a MESSAGE statement!

Posted by MBeynon on 08-Feb-2013 07:25

Hi,

I have some trigger code which calls a procedure. The problem is the trigger will not fire unless there is a MESSAGE statement either before the call to the procedure LoadXML or in the procedure itself!

This is very peplexing. Has anyone got some advice for me? The component firing the trigger is the System.Windows.Forms.ComboBox.

Many Thanks,

Mark.

P.S. The code....

    /*------------------------------------------------------------------------------
            Purpose:                                                                       
            Notes:                                                                       
    ------------------------------------------------------------------------------*/

    @VisualDesigner.
    METHOD PRIVATE VOID comboBox1_SelectedIndexChanged( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):

        LoadXML().

    END METHOD.


    /*------------------------------------------------------------------------------
            Purpose:                                                                       
            Notes:                                                                       
    ------------------------------------------------------------------------------*/

    METHOD PRIVATE VOID LoadXML(  ):

      DEFINE VARIABLE lvlGridSettingXMLasLongchar AS LONGCHAR NO-UNDO.

    FIND FIRST ttGridSetting NO-LOCK
      WHERE ttGridSetting.lvcSettingName = GetSelectedGridSettingNameValue() NO-ERROR.

    IF AVAILABLE ttGridSetting THEN
    DO:
      COPY-LOB FROM ttGridsetting.lvlXMLASCLOB TO lvlGridSettingXMLasLongchar.
     
      SetGridSettingsLongChar(lvlGridSettingXMLasLongchar).
    END. 
       
        RETURN.

    END METHOD.


  /*------------------------------------------------------------------------------
      Purpose: Accepts a longchar variable and uses it to create an XML document
               that the grid can load.                                   
      Notes:                                     
  ------------------------------------------------------------------------------*/


  METHOD PUBLIC VOID SetGridSettingsLongChar( INPUT iplcGridConfig AS LONGCHAR):
   
    DEFINE VARIABLE hDocMine                         AS HANDLE    NO-UNDO.
    DEFINE VARIABLE hRootMine                        AS HANDLE    NO-UNDO.
    DEFINE VARIABLE lvlResult                        AS LOGICAL   NO-UNDO.
   
    DEFINE VARIABLE lvcsetGridSettingsConfigFilePath AS CHARACTER NO-UNDO.   
   
    IF iplcGridConfig = ?
      OR iplcGridConfig = "" THEN
    DO:
      MESSAGE "An invalid value has been passed to SetGridSettingsLongChar"
        VIEW-AS ALERT-BOX. 
      RETURN.
    END.
   
    /* get the file path */
    lvcSetGridSettingsConfigFilePath = GetGridSettingsConfigFilePath().   
   
    CREATE X-DOCUMENT hDocMine.
    CREATE X-NODEREF hRootMine.
   
    lvlResult = hDocMine:LOAD("LONGCHAR",iplcGridConfig,FALSE) NO-ERROR.
   
    IF NOT lvlResult THEN
    DO:
      MESSAGE "An error has occured loading the grid configuration: " ERROR-STATUS:GET-MESSAGE(1)
        VIEW-AS ALERT-BOX.
      RETURN.
    END.   
   
    hDocMine:GET-DOCUMENT-ELEMENT(hRootMine).
   
    lvlResult = TRUE.
   
    lvlResult = hDocMine:SAVE("FILE", lvcSetGridSettingsConfigFilePath).
   
    IF NOT lvlResult THEN
    DO:
      MESSAGE "An error has occured loading the grid configuration: " ERROR-STATUS:GET-MESSAGE(1)
        VIEW-AS ALERT-BOX.
      RETURN.
    END.   
   
    ultraGrid1:DisplayLayout:LoadFromXml(lvcSetGridSettingsConfigFilePath).
   
    /* remove the temporary file now we've done with it  */
    OS-DELETE VALUE(lvcSetGridSettingsConfigFilePath) NO-ERROR.
   
    DELETE OBJECT hDocMine.
    DELETE OBJECT hRootMine.
   
    RETURN.

  END METHOD.

All Replies

Posted by Admin on 08-Feb-2013 07:29

PROCESS EVENTS .  ???

On 10.2B (latest service pack) you may need -IOEverywhere 1

Posted by MBeynon on 08-Feb-2013 08:02

This is the culprit:

GetGridSettingsConfigFilePath()

  RETURN THIS-OBJECT:comboBox1:SelectedText.

This only seems to return a value after a MESSAGE BOX has been called. Is it a focus issue?

I'm populating the combo like this:

arrayvar0[i] = STRING(lvhComboQuery:GET-BUFFER-HANDLE(1):BUFFER-FIELD("SettingName"):BUFFER-VALUE())

THIS-OBJECT:comboBox1:Items:AddRange(arrayvar0).

The combo displays the data OK but that's about it!

Mark.

P.S. I'm not sure about PROCESS EVENTS.

Posted by Admin on 08-Feb-2013 08:05

Use a PROCESS EVENTS statement instead of the MESSAGE Statement.

Posted by mopfer on 08-Feb-2013 09:49

PROCESS EVENTS often causes collateral damage, and can be a mask for a problem that would have been better solved than hidden.  If you need PROCESS EVENTS, then at least one event is not naturally firing as soon as the code assumes it would - the cart has gotten in front of the horse somewhere along the line. It almost always turns out to be a better idea to figure out why the event hasn't already fired and fix the process flow to work as expected.

Posted by mopfer on 08-Feb-2013 10:02

If you PUT the value of THIS-OBJECT:comboBox1:SelectedText to a file instead of displaying it in a message prior to the RETURN statement, you can see if the event that causes SelectedText to be populated has really happened or not.  If it has not, then maybe a different property can be used to get the value, or some harmless method can be invoked for comboBox1 to persuade the event that assigns the value to SelectedText to fire before the RETURN statement.

Posted by jquerijero on 20-Feb-2013 12:58

Where are you calling GetGridSettingsConfigFilePath() from?

This thread is closed