Page 1 of 1

Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 2:22 pm
by Rick Lipkin
To All

Using the DEFAULT clause on creating a button from code does not seem to work .. Default is on the Cancel button, not on OK ..

Rick Lipkin

Consider this code:

Code: Select all  Expand view


#Include "FiveWin.ch"

Static cSAY,oSay

//---------------
Func Main()

LOCAL oBtn1,oBtn2,oDlg

cSay := Space(30)


DEFINE DIALOG oDlg                          ;
       FROM 10, 2 to 30, 55                 ;
       TITLE "DEFAULT Button Test"           ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

   @ 3,3 Say oSay var cSay of oDlg

   @ 6,16 BUTTON oBtn1 Prompt "&Ok"         ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( nil )

   @ 6,23 BUTTON oBtn2 Prompt "&Cancel"     ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( oDlg:END() ) DEFAULT

ACTIVATE DIALOG oDlg

 


Image

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 4:09 pm
by frose
Rick,

try setting the 'DEFAULT' clause to the Ok-Button :wink:

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 6:31 pm
by Rick Lipkin
Frank

Strange error .. if you leave the dialog without any controls .. the above behavior is what you will get .. If you add a Get or a radio button the DEFAULT clause on the Cancel button works just fine.

Rick

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 7:13 pm
by Antonio Linares
Rick,

In your example you don't have an action for the OK button. It is nil.

Try it with this change:

@ 6,16 BUTTON oBtn1 Prompt "&Ok" ;
SIZE 30,25 of oDLG ;
ACTION MsgBeep()

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 7:19 pm
by Rick Lipkin
Antonio

No change on the default button by adding msgbeep() .. :( .. I noticed this as I was building the IE Page Scrape example for the forum .. Strangely.. when I added a control, the Cancel button showed up as Default.

Rick

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 7:24 pm
by Antonio Linares
Rick,

Please notice that such beahvior is controled fom METHOD KeyChar( nKey, nFlags ) CLASS TControl so until there is no a control on the dialog it may not get properly precessed.

If Class TButton uses a different Method KeyChar() that may explain the difference.

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 7:33 pm
by Rick Lipkin
Antonio

Thank you for your help !! I doubt if an empty dialog would ever occur... no need to spend any of your time on this..

I always create my forms from .rc and was trying to create a form from code .. As I was lining up the buttons I noticed the behavior .. as I started putting gets, says and radio buttons in the mix .. The Default worked.

Again, Many Thanks

Rick

Re: Pushbutton Default FWH 1201

PostPosted: Sat Feb 04, 2012 8:06 pm
by frose
Rick, Antonio,

it's (only) standard default behavior, if the focus is on a Button, the Button action will be triggered on VK_RETURN , NOT the Standard-Pushbutton!

So, everything is all right :)

See also sample:
Code: Select all  Expand view
Func Main()

   LOCAL oBtn1,oBtn2,oDlg

   cSay := Space(30)


   DEFINE DIALOG oDlg                          ;
       FROM 10, 2 to 30, 55                 ;
       TITLE "DEFAULT Button Test"           ;
       STYLE nOr( WS_POPUP,WS_CAPTION,WS_THICKFRAME )

   @ 3,3 Say oSay var cSay of oDlg

   @ 6,16 BUTTON oBtn1 Prompt "&Ok";
      SIZE 30,25;
      OF oDLG;
      ACTION( OkButton() )

   @ 6,23 BUTTON oBtn2 Prompt "&Cancel"     ;
       SIZE 30,25 of oDLG                   ;
       ACTION ( oDlg:END() )  DEFAULT

   ACTIVATE DIALOG oDlg
RETURN NIL

FUNCTION OkButton()
    MsgInfo( "Here is the Ok Button!" )
RETURN NIL