📄 twordrange.htm
字号:
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<meta name="Microsoft Border" content="none">
<title>TWordRange</title>
</head>
<body bgcolor="#FFFFCC">
<h1 align="center"><em><font color="#800000"><b>TWordRange</b></font></em></h1>
<p align="left"><font color="#804040"><big><strong><big><big><em>Methods</em></big></big></strong></big></font></p>
<p><tt>Constructor.CreateFromBookMark(WordDoc : TWordDoc; BookmarkName : String);</tt> <br>
<tt>Constructor.CreateFromSelection(WordDoc : TWordDoc);</tt> <br>
<tt>Constructor.CreateFromDoc(WordDoc : TWordDoc; iStart : Integer = 1; iEnd : Integer =
1);</tt> <br>
<tt>Constructor.CreateFromRange(WordDoc : TWordDoc; ComRange : Range);<br>
Destructor.Destroy; override;</tt></p>
<blockquote>
<p>These create/destroy new TWordRange objects. They will automatically add themselves to
the TWordDoc list of ranges and will remove themselves when you free them. </p>
</blockquote>
<p><tt>Collapse(oeDirection : TOleEnum = wdCollapseStart);<br>
EndOf(oeUnit : TOleEnum = wdWord; oeExtend : TOleEnum = wdMove) : Integer;<br>
Expand(oeUnit : TOleEnum = wdWord) : Integer;<br>
Move(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Integer;<br>
MoveWhile(Cset : String; Count : Integer = wdForward) : Integer;<br>
MoveUntil(Cset : String; Count : Integer = wdForward) : Integer;<br>
MoveStart(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Integer;<br>
MoveStartWhile(Cset : String; Count : Integer = wdForward) : Integer;<br>
MoveStartUntil(Cset : String; Count : Integer = wdForward) : Integer;<br>
MoveEnd(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Integer;<br>
MoveEndUntil(Cset : String; Count : Integer = wdForward) : Integer;<br>
MoveEndWhile(Cset : String; Count : Integer = wdForward) : Integer;<br>
SetRange(iStart, iEnd : Integer);<br>
StartOf(oeUnit : TOleEnum = wdWord; oeExtend : TOleEnum = wdMove) : Integer;</tt></p>
<blockquote>
<p>Various methods to move/extend the range. They act in the same way as the COM range
object methods. </p>
</blockquote>
<p><tt>GoTo_(oeWhat, oeWhich : TOleEnum; oeCount: Integer = 1; oeName: String = '') :
Range;<br>
GotoBookmark(BookmarkName : string) : range;<br>
GoToNext(oeWhat : TOleEnum) : Range;<br>
GoToPrevious(oeWhat : TOleEnum) : Range;<br>
Next(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Range;<br>
Previous(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Range;</tt></p>
<blockquote>
<p>Various methods to move/extend the range. They act in a similar way to the COM range
object methods. However the Word versions return the altered range object and do not
change the range object that they are called from. This leads to lots of objects floating
around - fine in the world of COM where they are cleared up automatically but in Delphi,
objects need to be explicitly cleared up. Instead of returning new TWordRange objects
(that you would need to free) these methods will alter their calling object's range as
well as returning the COM range object. You will usually throw away the COM range object
returned by treating the function as a procedure, but you may find it useful. There is
thus some inevitable duplication of methods here with the methods in the previous section.</p>
</blockquote>
<p><tt>GetNextRange(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Range;<br>
GetPreviousRange(oeUnit : TOleEnum = wdCharacter; oeCount : Integer = 1) : Range;</tt></p>
<blockquote>
<p>These methods return a COM range object without altering the calling TWordRange
object's range. You could combine these methods with CreateFromRange to get a TWordRange
object.</p>
</blockquote>
<p><tt>InsertAfter(Text : String);<br>
InsertAutoText;<br>
InsertGivenAutoText (AutoText : String; UseRichText : Boolean = True);<br>
InsertBefore(Text : String);<br>
InsertBreak(oeType : TOleEnum = wdPageBreak);<br>
InsertParagraph;<br>
InsertParagraphAfter;<br>
InsertParagraphBefore;<br>
InsertSymbol(CharacterNumber: Integer; Font: String; Unicode: Boolean = False; oeBias :
TOleEnum = wdFontBiasDefault);</tt></p>
<blockquote>
<p>Various methods to insert characters, text and symbols into the range. They act in the
same way as the COM range object methods. </p>
</blockquote>
<p><tt>Select;</tt></p>
<blockquote>
<p>Makes the Selection object the same as the range object.</p>
</blockquote>
<p><tt>Cut;<br>
Copy;<br>
Paste;</tt></p>
<p><tt>NoOfWords : Integer;</tt> </p>
<blockquote>
<p>Fairly obvious methods and functions</p>
</blockquote>
<p><tt>InsertGivenAutoText (AutoText : String; UseRichText : Boolean = True);</tt></p>
<blockquote>
<p>This will get the autotext assigned to the variable AutoText and insert it into the
range. If UseRichText is true then it uses the style stored with the autotext rather than
the style of the range. Note this will not be a very quick way of inserting lots of
autotext objects as it requires some late binding (see earlier info on attached
templates). However, autotext is a good way of allowing the inserted text to be modified
(by altering the template) without changing your program. NB when creating autotext
extries, make sure they are stored in the active template and not in normal.dot (or this
function will not see them). </p>
</blockquote>
<tt>
<p>CreateBookMark(Bookmark : String);</p>
</tt>
<p>Allows you to create a bookmark from a range. If you create a range from a bookmark and
then alter its text by using the text property, the bookmark is deleted. You can either
re-create it or use a bookmark that is just an insertion point and then use the
InsertAfter ('…') method to add text. Note that if you do this, the bookmark will
remain just an insertion point rather than the whole range added. </p>
<p><font color="#804040"><strong><big><big><em><big>Properties</big></em></big></big></strong></font></p>
<p><tt>WordDoc : TWordDoc read FWordDoc;</tt></p>
<blockquote>
<p>The parent TWordDoc that owns the WordRange object.</p>
</blockquote>
<p><tt>Start : Integer read GetStart write SetStart;<br>
End_ : Integer read GetEnd write SetEnd;</tt></p>
<blockquote>
<p>Allows you to alter the start and end characters of the range.</p>
</blockquote>
<p><tt>Text : String read GetText write SetText;</tt></p>
<p>Allows you to read/write the actual text of the range. Note that the text read is plain
ASCII (i.e., no special formatting is retrieved). Setting the Text will insert characters
in the prevailing font & style, etc.</p>
<p><tt>Bold : Boolean read GetBold write SetBold;<br>
Italic : Boolean read GetItalic write SetItalic;<br>
Underline : Boolean read GetUnderline write SetUnderline;<br>
Case_ : TOleEnum read GetCase write SetCase;<br>
Font : _Font read GetFont write SetFont;<br>
Style : String read GetStyle write SetStyle;</tt></p>
<blockquote>
<p>Reads/Sets these characteristics for the whole range. Note if some of the text is
italic and some is not, the property value will return false.</p>
</blockquote>
<p><tt>ItemIndex : Integer read FItemIndex;</tt></p>
<blockquote>
<p>Returns the index of the TWordRange object within the TWordDoc list.</p>
</blockquote>
<tt>
<p>property Range : Range;</p>
</tt>
<blockquote>
<p>This returns the actual COM Range object, if required. Can also be set (e.g., from one
of the functions that returns a COM range object). For example:</p>
<p><tt>RangeOne := TWordRange.CreateFromSelection(WordDoc);</tt> <br>
<tt>RangeTwo := TWordRange.CreateFromBookmark(WordDoc, 'Title');</tt> <br>
<tt>...</tt> <br>
<tt>RangeOne.Range := RangeTwo.GetNextRange;</tt></p>
</blockquote>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -