It is often useful to examine an EditField’s Text property, but you will not so often have occasion to set it. For one thing, this causes an annoying flicker as the entire EditField redraws itself. For another, it is usually overkill. Typically, you change an EditField’s text by selecting just a particular stretch of text and then manipulating the contents of the selection, using SelText, SelTextFont, and so forth.
To select a particular stretch of text means setting SelStart and SelLength. This may require some care. If you set the SelLength, you probably expect it to adopt the value you give it; and if you set the SelStart, you probably expect the SelLength to remain unchanged. But neither will necessarily be the case. In a single-line EditField, setting SelStart has the side effect of setting SelLength to zero. In a multiline EditField, that doesn’t happen, but slamming into the end of the text is of particular concern. For example, suppose a multiline EditField contains 10 characters. Consider the following sequence:
editfield1.selstart = 0 editfield1.sellength = 7// but not for long! editfield1.selstart = 7 editfield1.selstart = 0
Afterward, SelLength is
3. Similarly, giving
SelStart or SelLength a value that is too small can yield unusual
results; for instance, in a multiline field, this code:
editfield1.selstart = -1
moves the start of the selection to the start of the field and
reduces its length by
The rest of this section consists of examples ...