class RichEdit
Class RichEdit is a single or multi-line editor that can be used to create or edit data in the Microsoft Rich Text Format (RTF) or plain text
Syntax
[<oRef> =] new RichEdit(<container> [,<name expC>])
<oRef>
A variable or property—typically of Form, SubForm, Container, or Notebook—in which to store a reference to the newly created RichEdit object.
<container>
The container—typically a Form object—to which you’re binding the RichEdit object.
<name expC>
An optional name for the RichEdit object. If not specified, the RichEdit class will auto-generate a name for the object.
Property |
Default |
Description |
0 – None |
How the RichEdit object is anchored in its container (0=None, 1=Bottom, 2=Top, 3=Left, 4=Right, 5=Center, 6=Container)
|
|
RICHEDIT |
Identifies the object as an instance of the RichEdit class |
|
Window |
Background Color |
|
true |
Whether the RichEdit object is surrounded by the border specified by borderStyle |
|
bulletIndentSize |
180 |
Indent of paragraph when bullet list or numeric list is selected (in twips) |
(RICHEDIT) |
Identifies the object as an instance of a custom class. When no custom class exists, defaults to baseClassName |
|
true |
Whether pressing Tab follows CUA behavior and moves to next control, or inserts tab in text |
|
null |
The
Field object that is linked to the RichEdit objec. You can use
the datalink dialog to link to a table's field object, but not
to a document. to link to a document use.... |
|
indentSize |
180 |
Indent increment of paragraph used when applying indenting or outdenting (in twips) |
readOnly |
false |
Whether the text is editable or not |
popupEnable |
true |
Whether the RichEdit object’s context menu is available |
textType |
0 - RTF |
The
type of text to create or edit (0 - Rtf, 1 - Plain text). NOTE:
if datalinked to a text/character field will default to
1 - PlainText |
|
The data (either in rich text or plain text format) currently displayed in the RichEdit object |
Event |
Parameters |
Description |
<char expN>,<position expN>,<shift expL>,<ctrl expL> |
When a key is pressed in the RichEdit. Return value may change or cancel keystroke. |
|
<left expN> |
When the mouse button is released over the RichEdit's display area during a Drag&Drop operation |
|
|
When attempting to remove focus. Must return true, or focus remains.
|
|
Method |
Parameters |
Description |
|
Copies selected text to the Windows clipboard |
|
|
Cuts selected text and copies it to the Windows clipboard |
|
findText() |
<cFind>[, <lMatchCase>[, <lWholeWord>[, <lDirection>]]] |
Search specified
text (cFind) within RichEdit control's value. The search starts from the current cursor position. |
getLineCount() |
|
Returns the number of lines of text within the RichEdit control given the current width and formatting |
getLineFromChar() |
<nChar> |
Returns the zero based line number for the given zero based character index (nChar - offset from start of value) or if -1 is specified for nChar, returns the current line (the line containing the cursor). |
getLineIndex() |
<nLine> |
Returns the zero based character index for the start of line number nLine. If nLine is -1, returns the start of the current line (the line containing the cursor). |
getLineLength() |
<nLine> |
Returns the length for line number nLine. If nLine = -1, returns the length of the current line (the line containing the cursor). |
getParaAlignment() |
|
Returns the alignment value of the currently selected paragraph |
getParaBulleted() |
|
Returns true if the currently selected text is bulleted |
getParaNumbered() |
|
Returns true if the currently selected text is numbered |
getSel() |
<nStart>,<nEnd> |
Returns character
values for parameters nStart and nEnd specifying the start and
end positions of the current selection. You have to
initialize the nStart and nEnd parameter before calling this method.
EX.. |
getSelBold() |
|
Returns true if all the selected text is in bold. Otherwise returns false |
getSelColor() |
|
Returns the color value (in hexidecimal) of selected text if all the color is the same. Otherwise returns empty value. |
getSelFontName() |
|
Returns the font name of the currently selected text if all the text is of the same font. Otherwise returns empty value. |
getSelItalic() |
|
Returns true if all the selected text is italic. Otherwise returns false |
getSelHeight() |
|
Returns the height of the selected text if all the height is the same. Otherwise returns empty value |
getSelStrikeout() |
|
Returns true if all of the selected text has strikeout. Otherwise returns false |
getSelUnderline() |
|
Returns true if all of the selected text has underline. Otherwise returns false. |
getTextLength() |
|
Returns the length (in characters) of all the text in the RichEdit control. |
getTextRange() |
<nStart>, <nEnd>, <cVar> |
Returns the text
for the text range specified by the character index parameters
nStart and nEnd. The text is returned in parameter cVar and the
length of the returned text is the return value from this method.
cVar must be initiated before using it to get the text... |
<expC> |
Simulates typed user input to the RichEdit object |
|
|
Copies text from the Windows clipboard to the current cursor position |
|
print() |
|
Sends the richEdit data to printer. |
printPreview() |
|
Opens a print preview with the current value of the richEdit component. |
redo() |
|
Reverses the effects of the most recent undo() action |
save() |
|
If the RichEdit control is datalinked to a file, saves the contents of the control to the file. |
scroll() |
<nLines> [, <nChars>] |
Scrolls the contents of the RichEdit control up to nLines vertically and nChars horizontally. If nChars is not passed in, the default for it is zero. |
setParaAlignment() |
<nAlign> |
Sets alignment of text for the current or selected paragraphs. where nAlign is .. 1 - Left 2 - Right 3 - Centered 4 - Justified |
setParaBulleted() |
|
Sets paragraph bullets on or off for the current or selected paragraphs. |
setParaNumbered() |
|
Sets paragraph numbering on or off for the current or selected paragraphs. |
setSel() |
<nStart>, <nEnd> |
Selects text in range specified by nStart and nEnd. |
setSelBold() |
<lBold> |
Sets the bold attribute on or off for the current selection. lBold = True turns on the bold attribute and lBold = False turns off the bold attribute. |
setSelColor |
<cColor> |
Sets the text color (cColor) to apply to the current selection where cColor is a standard dBASE color string. |
setSelFont() |
<cFontName, size, attributes> |
sets font to getfont()
properties... <obj>.setSelFont(cFontStr) |
setSelFontName() |
<cFontName> |
Sets the fontname (cFontName) to apply to the current selection. |
setSelHeight() |
<nHeight> |
Sets the fontsize (nHeight) to apply to the current selection (in points). |
setSelItalic() |
<lItalic> |
Sets the italic attribute on or off for the current selection. lItalic = True turns on the italic attribute and lItalic = False turns off the italic attribute. |
|
Reverses the effects of the most recent cut( ), copy( ), or paste( ) action
|
NOTE: the Line and index values are all zero based. For Example - If you want to check the first line length the reference would be <obj>.getLineLength(0).
NOTE: The text formatting will only work when datalinked as follows:
When textType is set to 0 - Rtf:
File of type RTF
dBASE Memo field (if memo field has correct RTF header)
Paradox FMTMEMO field (BDE logical type: BLOB, logical subtype: FMTMEMO)
LongVarChar, or CLOB field in a database table
The text formatting will NOT work
When textType is set to 1 - Plain Text
File of type text
dBASE MEMO field (in a DBF) (if data is entered and there is no rtf header in the memo field data)
dBASE Character field (in a DBF)
VarChar and Other similar text type fields or CLOB fields in database tables
Or not datalinked to anything:
In this case, the value property can be used to load and access the text
within a richedit control
Description
The richEdit object can be datalinked to a table's field object if the field type is a text type of Character or Memo. It cannot be datalinked to an OLE or Binary field.
The search methods, copy, undo etc.. can be used with a datalinked text field or with a text file. But, the format settings can only be used with an .rtf file.
You can datalink any plain text file (like .txt, .log or other file that can be viewed as plain text). These always must be textType = 1 (plain text).
NOTE: initially setting datalink to .txt file ... does not automatically set the textType to 1 (plain text)
(has to be set by developer in inspector )
You can datalink any .rtf file that has the correct .rtf header
This header file looks something like..
{\rtf1\ansi\ansicpg1253\deff0\nouicompat\deflang1032{\fonttbl{\f0\fnil\fcharset161 Arial;}}
{\*\generator Riched20 10.0.16299}\viewkind4\uc1
\pard\f0\fs20\par
}
No other proprietary files (such as .doc or .xls etc.. ) can be opened in richEdit.
This form uses the richEdit object's onOpen event to link to a Text or Rtf file.
** END HEADER -- do not remove this line
//
// Generated on 11/27/2017
//
parameter bModal
local f
f = new richfileForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class richfileForm of FORM
with (this)
height = 18.5909
left = 66.0
top = 0.7273
width = 53.5714
text = ""
endwith
this.RICHEDIT1 = new RICHEDIT(this)
with (this.RICHEDIT1)
onOpen = class::RICHEDIT1_ONOPEN
height = 18.5
left = 0.0
top = 0.0
width = 53.2857
anchor = 6 // Container
endwith
function RICHEDIT1_onOpen()
local isRtf, ext
ext = ""
ifRtf = true
f = getfile("*.*","Choose file to open")
if not empty(f)
this.datalink = null
ext = upper(substr(f,rat(".", f)+1))
isRtf = iif(ext == "RTF", true, false )
this.textType = iif(isRtf, 0, 1)
this.datalink = 'FILE '+f
endif
return
endclass
Go Here for a more detailed example.