Page 1 of 1

DCREAD GUI - ACTION OF THE OK BUTTON AND THE CANCEL BUTTON

Posted: Sun Oct 30, 2016 7:44 am
by alepap
With Express, when using
DCREAD GUI ;
ADDBUTTONS

You get a Ok Button and a Cancel Button.

1) What are the ACTION of these Buttons?

2) How can I find out what is the ACTION of a button, where is it located?

Thank you,

Alexandre

Re: DCREAD GUI - ACTION OF THE OK BUTTON AND THE CANCEL BUTT

Posted: Sun Oct 30, 2016 8:01 am
by rdonnay
If you look at line 3425 of _DCGETBX.PRG, this is where those buttons are created.

They are added to the GetList.

The ACTION for the OK button is {||DC_ReadGuiExit(self)}
The ACTION for the CANCEL button is {||DC_ReadGuiAbort(self)}

This is functionally equivalent to:

{||DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

and

{||DC_ReadGuiEvent(DCGUI_EXIT_ABORT,GetList)}


If you wish to change the ACTION clause you can override it by adding your own buttons with the BUTTONS clause.

Another trick, is to search for the buttons and change the action clause.

DCREAD GUI EVAL {||ChangeOKButtonAction(GetList)}

* -----------

FUNCTION ChangeOKButtonAction(GetList)

oButton := DC_GetObject(GetList,'DCGUI_BUTTON_OK')
oButton:activate := {||MsgBox('You are OK to leave this window'),DC_ReadGuiEvent(DCGUI_EXIT_OK,GetList)}

RETURN nil

Re: DCREAD GUI - ACTION OF THE OK BUTTON AND THE CANCEL BUTT

Posted: Sun Oct 30, 2016 8:44 am
by alepap
Thank you Roger.

For the readers of this Subject, there is a sample in xDemo
In Samples Set 2
In ArrayEdit number 49

Code: Select all

ELSEIF nAction = 9 // Exit and Save

  IF DC_MsgBox(,,{'Exit and Save Changes?'},,,,.t.)
    DC_ReadGuiEvent(DCGUI_EXIT_OK,aGetList)
  ENDIF
  RETURN .t.

ELSEIF nAction = 10 // Exit and Abort

  IF DC_MsgBox(,,{'Exit and Abort Changes?'},,,,.t.)
    DC_ReadGuiEvent(DCGUI_EXIT_ABORT,aGetList)
  ENDIF
  RETURN .t.

This is helpful when you whant to terminate the DCREAD GUI by another BUTTON.

Than you would have something like this in BUTTON before the DCREAD GUI

Code: Select all

   @ 27,135 DCPUSHBUTTON CAPTION 'PGDN' SIZE 9,1.2 ;
         ID 'PAGE_DN' ;
         ACTION {|| sSCRGUI_PGDN(GetList) }
and the function would look like this

Code: Select all

FUNCTION sSCRGUI_PGDN(aGetlist)

   DC_ReadGuiEvent(DCGUI_EXIT_OK,aGetList)  // this terminates the DCREAD
   zEPGDN() // this is just another function that I execute...

RETURN .T.
Choo-Choo

Re: DCREAD GUI - ACTION OF THE OK BUTTON AND THE CANCEL BUTT

Posted: Sun Oct 30, 2016 12:05 pm
by Cliff Wiernik
I use the add buttons when I simply what an OK or cancel. However, if you want to validate something upon clicking OK, I usually add my own buttons in order to give the desired level of control I need prior to the dialog exiting and clearing. If I control the action, I am still in the dialog and can act according.