1

Konu: Clicking on "white space" within a commandgroup

Hello:

The text

"In Visual FoxPro 3, the .Value of a Command Group corresponds to the most recently pressed button. A developer could code the Click logic for all contained buttons in the Command Group's .Click method, perhaps using a DO CASE. If the Command Group.Value were initialized to 0 at design time, then reset to 0 after processing the Click, the logic could be coded so as to trap .Value = 0 as a click on "white space" within the group. If the .Value is not explicitly reset to 0 after a button has been pressed, any clicks on "white space" thereafter will trigger a .Click() event with the .Value still corresponding to whatever button was most recently pressed."

(http://fox.wikis.com/wc.dll?Wiki~CommandGroup)

describes my situation:

"any clicks on "white space" thereafter will trigger a .Click() event with the .Value still corresponding to whatever button was most recently pressed."

My code is

Visual Fox Pro
 

DEFINE CLASS clDataCmdGrp AS Hanscommandgroup OF "D:\Databases\Class libraries\Hans VFP Common Classes\HansBaseClasses.VCX"
ButtonCount = 4 && **********  ADD NUMBER OF MENU BUTTONS HERE!  ***********
    PROCEDURE Click &&  ************  ADD CLICK COMMAND FOR EACH CASE HERE  *************
        DO CASE
            CASE This.Value = 1  && Delete
                MESSAGEBOX('Add command here – 1')
            CASE This.Value = 2  && Save
                MESSAGEBOX('Add command here – 2')
            CASE This.Value = 3  && Quit
                MESSAGEBOX('Add command here – 3')
            CASE This.Value = 4  && Edit
                MESSAGEBOX('Add command here – 4')
        ENDCASE
    ENDPROC
ENDDEFINE

Visual Fox Pro
 


(Messageboxes are temporary.)

I am not sure where to reset the commandgroup's value to 0 (if that is what to do) or, as is said in the book "Hacker's Guide  ...", not use Commandgroups (almost) at all.

Regards,

Hans L

2

Re: Clicking on "white space" within a commandgroup

Hans,
That setting value to 0 woudn't work anyway. Been there done that. And I am not against CommanGroup usage, I find it very practical to have click code for a group of related buttons in a single place and use the CommandGroup myself. Here is how you would code against white space click:

Visual Fox Pro
DEFINE CLASS clDataCmdGrp AS Hanscommandgroup OF "D:\Databases\Class libraries\Hans VFP Common Classes\HansBaseClasses.VCX"

ButtonCount = 4 && ********** ADD NUMBER OF MENU BUTTONS HERE! ***********
PROCEDURE Click && ************ ADD CLICK COMMAND FOR EACH CASE HERE *************
Local loObject
    loObject = Sys(1270)
    If ( TYPE('m.loObject') = 'O' AND !ISNULL(m.loObject) AND m.loObject != This ) && not White space
      Do Case
        Case This.Value = 1 && Delete
          Messagebox('Add command here – 1')
        Case This.Value = 2 && Save
          Messagebox('Add command here – 2')
        Case This.Value = 3 && Quit
          Messagebox('Add command here – 3')
        Case This.Value = 4 && Edit
          Messagebox('Add command here – 4')
        Otherwise  && Added just for flexibility - someone might change the buttoncount but forget to add case
          Messagebox('Forgot to add command for ' + ltrim(str(This.Value)))
      Endcase
    Endif
endproc
enddefine

3

Re: Clicking on "white space" within a commandgroup

Thanks, Cetin.

I noticed that setting value to 0 did not work (I tried it after my posting).

I'll recode as you suggest.

Regards,

Hans L

4 Son düzenleyen, Hans L (14.02.2011 21:29:47)

Re: Clicking on "white space" within a commandgroup

Cetin, somewhere I read that

"Starting in VFP 6, the test is much easier. You can use IF VARTYPE(oObject) = "O", because VARTYPE() returns "X" for any variable with a null value." Is this still true?

Now, your code works for whitespace, but when I have a disabled button (Enabled = .F.), and I click on that button, it works as before when I clicked at whitespace.  So, I added this

Visual Fox Pro
AND m.loObject.Enabled = .T.


to

Visual Fox Pro
If ( TYPE('m.loObject') = 'O' AND !ISNULL(m.loObject) AND m.loObject != This )


and it seems to work.

Regards,

Hans L

5

Re: Clicking on "white space" within a commandgroup

Yes you can use VarType(). Then it would look like:

Visual Fox Pro
If (VARTYPE(m.loObject) = 'O' AND m.loObject != This AND m.loObject.Enabled)