eventsclarion

Programmatically fire button click event


Is there a way to fire a button click event programmatically in Clarion? I've tried the following but they haven't worked:

! Doesn't work:
?ResetInput

! Also doesn't work:
?ResetInput:Accepted

Solution

  • I figured out a solution after a few hours of searching:

    POST(EVENT:Accepted, ?ResetInput)
    

    Please post any other answer if there's a more correct way of doing this.


    Here's the info regarding the POST function from the Clarion help docs:

    POST( event [,control] [,thread] [,position] )

    event: An integer constant, variable, expression, or EQUATE containing an event number. A value in the range 400h to 0FFFh is a User-defined event.

    control: An integer constant, EQUATE, variable, or expression containing the field number of the control affected by the event. If omitted, the event is field-independent.

    thread: An integer constant, EQUATE, variable, or expression containing the execution thread number whose ACCEPT loop is to process the event. If omitted, the event is posted to the current thread.

    position: An integer constant, EQUATE, variable, or expression containing either zero (0) or one (1). If one (1), the event message is placed at the front of the event message queue. If omitted or zero (0), the event message is placed at the end of the event message queue.

    POST posts an event to the currently active ACCEPT loop of the specified thread. This may be a User-defined event, or any other event. User-defined event numbers can be defined as any integer between 400h and 0FFFh. Any event posted with a control specified is a field-specific event, while those without are field-independent events.

    POSTing an event causes the ACCEPT loop to fire but does not cause the event to "happen." For example, POST(EVENT:Selected,?MyControl) executes any code in EVENT:Selected for ?MyControl but does not cause ?MyControl to gain focus.

    Example:

    Win1 WINDOW('Tools'),AT(156,46,32,28),TOOLBOX
        BUTTON('Date'),AT(0,0,,),USE(?Button1)
        BUTTON('Time'),AT(0,14,,),USE(?Button2)
    END
    
    CODE
        OPEN(Win1)
        ACCEPT
    
        ! Detect user-defined event:        
        IF EVENT() = EVENT:User THEN BREAK END
    
        CASE ACCEPTED()
        OF ?Button1
            POST(EVENT:User,,UseToolsThread)  !Post field-independent event to other thread
        OF ?Button2
            POST(EVENT:User) ! Post field-independent event to this thread
        END
    END
    
    CLOSE(Win1)