Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Subclassing OptionButton
Message
From
07/10/1998 03:03:08
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/10/1998 11:26:20
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00143846
Message ID:
00144465
Views:
24
>>>>>Am trying to add an OptionGroup to my class library and want to incorporate my own properties & methods with the associated OptionButtons.
Snip...
>
>Got the above to work with some minor modifications (such as the names of the buttons being removed and added in the FOR...ENDFOR loop cannot be exactly the same), BUT after saving the form and reopening it, the buttons revert to the standard VFP class. This happens whether I use the standard VFP optiongroup as a starting point or whether I use my own optiongroup as a starting point in the form designer. It's as though VFP won't let me substitute my own optionbuttons for the standard optionbuttons.
>
>In the meantime I've created nine optiongroup classes with from 2 to 10 buttons incorporating the event coding I wanted. Unfortunately I'm not able to add my own properties to the buttons, but can work around this limitation.
>
>- Werner
Werner,
After your warning I rechecked and faced the reality. Yes it's harder than it sounds with optionbuttons. Well I cannot call it a bug, probably missing something but cannot add an optionbutton class to an optiongroup, found a workaround though. It's not very smart but can be lived with. First create a class based on optionbutton (dummy) and only set properties as you want (not event, methods unless have it as a code holder). During design add optiongroup(s) to your form + that dummy button. If you want codes for each button, go and change the codes in that dummy (+ any properties you want). Then select optiongroup(s) + that dummy button in form, go to command window and run this code :
ASELOBJ(aOptGrp)
FOR ix = 1 to alen(aOptGrp)
  IF lower(aOptGrp[ix].baseclass) = "optionbutton"
    loOptButton = aOptGrp[ix]
  ENDIF
ENDFOR
IF !type("loOptButton") = "O"
  MESSAGEBOX("No definition object")
  RETURN
ENDIF
lnMembers = amembers(aPEM,loOptButton,1)
FOR each oObject in aOptGrp
  IF lower(oObject.baseclass) # "optiongroup"
    LOOP
  ENDIF
  WITH oObject
    N=0
    FOR each oButton in .buttons
      FOR ix = 1 to lnMembers
        IF pemstatus(oButton, aPEM[ix,1], 5) ;
            and !pemstatus(oButton, aPEM[ix,1], 2)
          IF pemstatus(oButton, aPEM[ix,1], 3) = "Property"
            IF !pemstatus(oButton, aPEM[ix,1], 1) ;
                and !inlist(aPEM[ix,1],"NAME","CAPTION")
              lcExpression = loOptButton.readexpression(aPEM[ix,1])
              IF type("lcExpression")="C" and !empty(lcExpression)
                oButton.writeexpression(aPEM[ix,1],lcExpression)
              ELSE
                IF getpem(loOptButton,aPEM[ix,1]) # getpem(oButton,aPEM[ix,1])
                  oButton.&aPEM[ix,1] = getpem(loOptButton,aPEM[ix,1])
                ENDIF
              ENDIF
            ENDIF
          ELSE
            lcMethod = loOptButton.readmethod(aPEM[ix,1])
            IF !empty(lcMethod)
              oButton.writemethod(aPEM[ix,1],lcMethod)
            ENDIF
          ENDIF
        ENDIF
      ENDFOR
      oButton.Top  = n * (oButton.height + 2) + 5
      N = n + 1
    ENDFOR
    .setall("left",5)
    .autosize = .t.
  ENDWITH
ENDFOR
Release oButton, loOptButton, oObject
Now you can delete that dummy from form. There should be an easier way but this is what I got for now. Hope helps.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform