Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Read-only Edit Boxes (Functions/Subroutines/Programs) ====== ====== ====== ==== Created at 11 OCT 1996 04:59PM ==== **Introduction** The edit box control has a check-box for "Read Only" in Form Design mode. This article describes how to toggle the read-only attribute at run-time. **Invisible, Disabled, and Read-Only** There are three simple ways to keep the user from editing data that is in a control on a form. Each has a different purpose: |Invisible|Not showing the control implies is a visual clue that the user shouldn't be able to see or update the data. For example, sensitive information in a secure system. | |Disabled |Disabling the control is a visual clue that the data in the control is somehow unapplicable to the present state of the form. For example, the Position, Width, and Height details on the first tab of the Popup Designer. | |Read-Only|Read-only is not a visual clue; the user can only tell that it is read-only when they start typing and nothing happens. The implication of read-only is that the data is the result of a calculation (and therefore can't be updated) or that the user is not supposed to be able to change the information, but **is** supposed to be able to read the information, scroll through the information, etc.| The problem with disabling an edit box is that it does not allow the edit box to be scrolled. Setting the edit box to read-only instead of disabled allows the user to scroll horizontally and vertically using the auto-scroll feature or the scroll bars. The user can also select text and copy text to the clip-board. **Implementing Read-Only Edit Boxes** The following function can be used to toggle the read-only setting of an edit box: function SetReadOnly(CtrlEntID, ReadOnly) declare function Get_Property declare subroutine SendMessage $insert Logical $insert PS_Equates $insert Ctrl_Property_Equates equ WM_USER$ to 1024 equ EM_SETREADONLY$ to WM_USER$ + 31 if assigned(CtrlEntID) else return FALSE$ end Handle = Get_Property(CtrlEntID, HANDLE$) if Handle else return FALSE$ end * default read-only to true * (assume if it isn't passed that the user is setting the * control to read-only, as implied by the function name) if assigned(ReadOnly) else ReadOnly = "" end if len(ReadOnly) then * efficient way to make sure that ReadOnly is boolean ReadOnly = not(not(ReadOnly)) end else ReadOnly = TRUE$ end Type = Get_Property(CtrlEntID, TYPE$) begin case case Type = PSCTL_EDITBOX$ * use the Windows SendMessage function to toggle the read-only * state of the edit box SendMessage(Handle, EM_SETREADONLY$, ReadOnly, 0) * read-only processing for other controls could be placed here * case Type = ... case OTHERWISE$ return FALSE$ end case return TRUE$ **Using the SetReadOnly Function** The following form, which has no code on it, shows how to use the SetReadOnly function: {{Missing - https://o4w.revelation.com/o4wtrs/KB_Articles/KB0039_files/image010.png?310x118}} Place an edit box on a new form, and set the name to EDITBOX_1 (which is the default name for the first edit box). Then place two buttons on the form. The first, titled "Read-Only", has the following Quick-Event: {{Missing - https://o4w.revelation.com/o4wtrs/KB_Articles/KB0039_files/image012.png?620x335}} The second, titled "Edit-Able", has the following QuickEvent: {{Missing - https://o4w.revelation.com/o4wtrs/KB_Articles/KB0039_files/image014.png?620x335}} **Source Files** [[http://o4w.revelation.com/o4wtrs/KB_Articles/KB0039_files/ReadOnly.txt|**{{Missing - https://o4w.revelation.com/o4wtrs/KB_Articles/KB0039_files/image016.png?78x48}}**]]**** ** ** **Special Thanks** To Luke at PSD Systems, who originated the article. kb/kb_articles/kb0039.txt Last modified: 2024/01/30 13:36by 127.0.0.1