ActiveDocument Object

The ActiveDocument object is used to refer to the document currently being displayed in the editor. To access an open document that isn't active, use the Application.DocumentCache object.

Properties

CanRedo (WordBool, read-only)

Returns True if changes can be re-done.

CanUndo (WordBool, read-only)

Returns True if changes can be undone.

Filename (OleString, read-only)

Returns the filename of the active document.

Lines[Index: integer] (OleString)

Gets/sets the text of the line at the passed index.

Note Iterating through a document using the Lines property may be slow, especially for large documents. It is recommend that you only use Lines to evaluate single lines of text. If you must use Lines to update many lines, you can boost performance by wrapping the update in a BeginUpdate..EndUpdate block.

LineCount (integer, read-only

Returns the number of lines in the active document.

Modified (WordBool, read-only)

Returns True if the document has been changed since it was last saved.

ReadOnly (WordBool, read-only)

Returns True if the active document is read-only.

SelStart (integer)

Gets/sets the start of the current selection.

SelLength (integer)

Gets/sets the length of the current selection

SelText (OleString)

Gets/sets the text in the current selection.

TabIndex

Gets/sets the tab index of the document tab.

Text (OleString)

Gets/sets the complete document text.

Methods

BeginUpdate

procedure BeginUpdate;

Turns off screen updating for the active document. This is useful if your script needs to make several changes to the active document at once - turning off screen updating during the procedure may significantly speed things up. To turn updating back on, use EndUpdate.

Note Use BeginUpdate...EndUpdate with caution. If you fail to call EndUpdate after a call to BeginUpdate, or if the script crashes before EndUpdate is called, the user will be unable to see any changes made in the editor.

Clear

procedure Clear;

Clears all text form the active document.

Close

function Close(wbPromptToSave: WordBool): WordBool;

Closes the active document. If wbPromptToSave is True, the user is prompted to save any changes. Returns True if the document was closed (that is, the user didn't cancel saving changes).

EndUpdate

procedure EndUpdate;

Turns on screen updating for the active document.

GetCaretPos

procedure GetCaretPos(var x, y: integer);

Returns the caret pos (x=column, y=line).

GetCurrentChar

function getCurrentChar: OleVariant;

Returns the current character.

GetNextChar

function GetNextChar: OleVariant;

Returns the next character. Note that this function (along with GetPreviousChar) can be slow when used in long loops.

GetPreviousChar

function GetPreviousChar: OleVariant;

Returns the previous character.

GotoNextEndTag

function GotoNextEndTag(wbSelect: WordBool): WordBool;

Moves the next end tag, selecting it if wbSelect is True. Returns False if no tag found.

GotoNextStartTag

function GotoNextStartTag(wbSelect: WordBool): WordBool;

Moves the next starting tag, selecting it if wbSelect is True. Returns False if no tag found.

GotoPreviousEndTag

function GotoPreviousEndTag(wbSelect: WordBool): WordBool;

Moves the previous end tag, selecting it if wbSelect is True. Returns False if no tag found.

GotoPreviousStartTag

function GotoPreviousStartTag(wbSelect: WordBool): WordBool;

Moves the previous starting tag, selecting it if wbSelect is True. Returns False if no tag found.

Indent

procedure Indent;

Indents the current selection.

InsertTag

procedure InsertTag(sStartTag, sEndTag: OleVariant; wbOverwriteSelection: WordBool);

Inserts the passed tag pair at the current cursor position, overwriting the selection if wbOverwriteSelection is True. The cursor will be positioned between the start and end tags after this operation, and if wbOverwriteSelection is False, the current selection will be surrounded by the tags.

InsertText

procedure InsertText(InsertStr: OleVariant; wbOverwriteSelection: WordBool);

Inserts the passed string at the current cursor position, overwriting the selection if wbOverwriteSelection is True.

LastSavedDate

Returns the datetime value for the last save of the document file.

Print

procedure Print(wbNoPrompt: WordBool);

Prints the active document. Prompts the user for print settings unless wbNoPrompt is True.

Redo

procedure Redo;

Performs a single redo operation.

Reload

procedure Reload(wbPromptToSave: WordBool);

Reloads the active document, prompting to save changes if wbPromptToSave is True.

ReplaceAll

function ReplaceAll(strSearch, strReplace: OleVariant; bMatchCase: WordBool): Integer;

Replaces all occurrences of strSearch with strReplace, matching case if bMatchCase is True. Returns the number of replacements made.

Save

function Save: WordBool;

Saves changes to the active document, returning True if successful.

SaveAs

function SaveAs(wsFileName: widestring): WordBool;

Saves changes to the active document to the file specified in the wsFileName parameter, returning True if successful. If wsFileName is empty, the standard "Save As" dialog box will be displayed to the user. Note that existing files will be overwritten by this function, so use with caution!

SelectAll

procedure SelectAll;

Selects all the text in the active document,

SelectCurrentLine

procedure SelectCurrentLine;

Highlights the current line.

SelectLine

procedure SelectLine(Index: Integer);

Highlights the passed line.

SetCaretPos

procedure SetCaretPos(x, y: Integer);

Sets the current column/line.

TextPosToEditorPos

Converts an index in a text string in a script to the corresponding editor position, taking tabs and newlines, which count as two characters in the text but only as one in the editor, into account. For instance, the number used in the Javascript charAt() function.

Undo

procedure Undo;

Performs a single undo operation.

Unindent

procedure Unindent;

Unindents the current selection.

Cursor Movement Procedures

Use these methods to position the cursor. If wbSelect is True, then the current selection will be extended to the new cursor position.

procedure CursorDocEnd(wbSelect: WordBool);

procedure CursorDocStart(wbSelect: WordBool);

procedure CursorDown(wbSelect: WordBool);

procedure CursorLeft(wbSelect: WordBool);

procedure CursorLineEnd(wbSelect: WordBool);

procedure CursorLineStart(wbSelect: WordBool);

procedure CursorPageDown(wbSelect: WordBool);

procedure CursorPageUp(wbSelect: WordBool);

procedure CursorRight(wbSelect: WordBool);

procedure CursorUp(wbSelect: WordBool);

procedure CursorWordLeft(wbSelect: WordBool);

procedure CursorWordRight(wbSelect: WordBool);