Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MAKING TEXTBOXES READ ONLY
Message
From
11/09/1997 17:32:21
Bob Lucas
The WordWare Agency
Alberta, Canada
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00049532
Message ID:
00049671
Views:
59
>>>>>nOW nNow that I have my own customized toolbar with subclasses, how do I make all the textboxes on a certain form readonly?
>>>>
>>>>Have you tried thisform.SetAll("ReadOnly", .t. ,"YourTextBoxClassName") ?
>>>
>>>That's the example I was looking for. It worked, thanks!
>>>How bout if I wanted only selected ones to be readonly, I guess Mr. Fournier's advice might apply.
>>
>>
>>In my base form class I have a method called 'changestate' which takes a parameter that indicates if the form should be in View or Edit mode. Based on the mode, it cycles through all fields and containers and sets the readonly property to true or false. I skip labels, and command buttons, because I generally want to handle my command buttons differently. Also, I have access codes assigned to each field so if the user does not have the appropriate access, the readonly property stays readonly. Remember that check boxes (or is it comboboxes?) do not have a readonly property so they must be handled differently.
>
>SOUNDS useful. what exactly does this 'changestate' method look like?


*-- This method changes the state of an object.
*-- It traverses a passed in object and sets properties depending upon
*-- the status of the object.

*-- uses recursive calls for container objects like pageframes
*-- also, my base classes have a couple of custom properties like laccessallowed, laccessvalidated and caccesscode
*-- these are used to determine access rights to the fields. There is a global array called lasysacces that stores the valid
*-- access codes for the current user.

*-- some fields are forced as read only at all times. (display fields). I do this by setting the laccessvalidated to .t. meaning the
*-- field has been validated and setting laccessallowed to .f. meaning no access to the field. This has the effect of leaving
*-- the field read only at all times.

*-- a special property called readonlyprop is added to comboboxes to simulate a readonly property
*-- for these objects, their when clause will have have: RETURN !readonlyprop

LPARAMETERS TO, tcstate, tlcalledfrominit

LOCAL lnControlCount, lncnt, lcClass, loObject

*-- Scan through containers controls and set control source

IF !PEMSTATUS(TO, "CONTROLCOUNT", 5) OR PEMSTATUS(TO, "CONTROLCOUNT", 2)
RETURN
ENDIF

lnControlCount = TO.CONTROLCOUNT

*-- set the global state
THISFORM.cmode = tcstate

FOR lncnt = 1 TO lnControlCount
lcClass = PROPER(TO.CONTROLS(lncnt).BASECLASS)

DO CASE

*-- If this is a PageFrame traverse all pages of control.
CASE lcClass == "Pageframe"
LOCAL lnPageCount, lncnt2
lnPageCount = TO.CONTROLS(lncnt).PAGECOUNT

*-- Traverse pages of pageframe
FOR lncnt2 = 1 TO lnPageCount
*-- Recursive Call
THIS.ChangeState(TO.CONTROLS(lncnt).PAGES(lncnt2), tcstate, tlcalledfrominit)
ENDFOR

CASE lcClass == "Container"
THIS.ChangeState(TO.CONTROLS(lncnt), tcstate, tlcalledfrominit)

CASE lcClass == "Label"
*-- do nothing with labels

CASE lcClass == "Grid"
*-- do nothing with grids

CASE lcClass == "Commandbutton"
*-- special behaviour for command buttons

loObject = TO.CONTROLS(lncnt)

IF loObject.laccessallowed OR tcstate = "Edit" OR tcstate = "New"
loObject.ENABLED = .T.
ELSE
loObject.ENABLED = .F.
ENDIF

OTHERWISE

*-- Set enable state of controls
*-- or set readonly property to false

loObject = TO.CONTROLS(lncnt)

IF PEMSTATUS(loObject, "ReadOnly", 5)

IF tcstate = "Edit" OR tcstate = "New"

IF PEMSTATUS(loObject, "cAccesscode", 5)

IF !loObject.laccessvalidated
loObject.laccessvalidated = .T.

IF ASCAN(laSysAcces, loObject.cAccessCode) > 0
loObject.laccessallowed = .T.
ENDIF

ENDIF

IF loObject.laccessallowed
loObject.READONLY = .F.

*-- for drop down combo boxes!

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .F.
ENDIF

ENDIF

ELSE
loObject.READONLY = .F.

*-- for drop down combo boxes!

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .F.
ENDIF

ENDIF

ELSE
loObject.READONLY = .T.

*-- for drop down combo boxes!

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .T.
ENDIF

ENDIF

ELSE
*-- for controls like check boxes

IF PEMSTATUS(loObject, "Enabled", 5)

IF tcstate = "Edit" OR tcstate = "New"


IF PEMSTATUS(loObject, "cAccesscode", 5)

IF !loObject.laccessvalidated
loObject.laccessvalidated = .T.

IF ASCAN(laSysAcces, loObject.cAccessCode) > 0
loObject.laccessallowed = .T.
ENDIF

ENDIF


IF loObject.laccessallowed

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .F.
ELSE
loObject.ENABLED = .T.
ENDIF
ENDIF

ELSE

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .F.
ELSE
loObject.ENABLED = .T.
ENDIF

ENDIF

ELSE

IF PEMSTATUS(loObject, "ReadOnlyprop", 5)
loObject.readonlyprop = .T.
ELSE
loObject.ENABLED = .F.
ENDIF

ENDIF

ENDIF

ENDIF

ENDCASE

ENDFOR

RETURN
Previous
Reply
Map
View

Click here to load this message in the networking platform