sgNeoWordEditor

Rich text and Word documents for VisualNEO Win · plug-in version 2.2 · LIS Software Lab

Introduction

sgNeoWordEditor puts a word processor into a VisualNEO Win publication. It is based on the Windows RichEdit control (Msftedit.dll), which is part of every Windows version. It opens and saves Word (.docx), RTF and text files. It exports to PDF, HTML and Markdown, and it prints with headers and footers. It also has spell checking, tables, pictures, OLE objects, hyperlinks, a ruler, a formatting toolbar and a Word-style page view.

Each editor sits on a Rectangle object on a page. A publication can have several editors at once, one per Rectangle. Every command names the Rectangle as its first parameter.

Requirements. VisualNEO Win with the plug-in installed (App › Plug-Ins › Install). Windows 8 or later for spell checking; Windows 10/11 have everything else built in. Vector PDFs use the Microsoft Print to PDF printer when it is installed; otherwise PDFs are made from page images automatically.

Getting started

  1. Draw a Rectangle on the page, for example Rectangle1. Its size is the size of the editor.
  2. In the page's Page Enter actions, open the editor. Then load a document, or start a new one:
sgEditorOpen "Rectangle1" "[DocText]" "" "Single" "True" "" "" "Centimeters" "" "True"
sgEditorPageView "Rectangle1" "FitWidth" ""
sgEditorLoadFile "Rectangle1" "[PubDir]Welcome.docx" "[Loaded]"
sgEditorSetFocus "Rectangle1"
  1. Add buttons that call commands. Examples: sgEditorSetFontStyle "Rectangle1" "ToggleBold", or sgEditorSaveFile "Rectangle1" "" "[Saved]" to save to the file that was loaded.
  2. On Page Exit you can use sgEditorClose "Rectangle1" "Hide". The document is kept, and the next sgEditorOpen shows it again. Use "Free" to discard it.

The plug-in's own toolbar (sgEditorOpen parameter Toolbar = True) already has font, style, alignment, list, indent, colour, link, undo and page-view buttons. You only need your own buttons for anything else.

How parameters work

TopicRule
RectangleThe first parameter of every command is the name of the Rectangle object the editor is attached to.
VariablesParameters marked variable take a VisualNEO variable in brackets, such as [Result]. The plug-in writes the answer into it.
Read or setCommands described as get or set (sgEditorZoom, the indent commands, sgEditorLineSpacing, sgEditorSelStart, sgEditorSelLength) look at the variable first. If it holds -1 or is empty, the current value is read into it. Any other value is applied.
ColoursR,G,B (for example 192,0,0), #RRGGBB, a Delphi colour name such as clNavy, or a number. Where a command reads a colour back, you get R,G,B.
UnitsIndents and table column widths use the measurement units chosen in sgEditorOpen: Pixels, Inches, Centimeters or Points.
True / FalseTrue, Yes or 1 switch an option on. Anything else switches it off.
ErrorsWhen a command fails, the reason is written to [LastError]. sgEditorLoadFile and sgEditorSaveFile also return True/False in their variable.
Header / footerleft|center|right, with the tokens {page}, {pages}, {date}, {time} and {title}. Example: |Page {page} of {pages}|.

Variables set by the plug-in

VariableSet whenHolds
[LastError]a command failsthe error message
[Rectangle1.PlugInVersion]sgEditorOpenplug-in version (2.2)
[Rectangle1.WinHandle]sgEditorOpenwindow handle of the RichEdit control
[Rectangle1.FileName]load, save, new documentthe current document file ('' = not saved yet)
[sgFontName] [sgFontSize] [sgFontStyle] [sgAlignment] [sgSelStart] [sgSelLength] the caret or selection moves (only when an OnFormat subroutine is given in sgEditorOpen) the formatting at the caret; then the OnFormat subroutine runs. Use it to update your own toolbar.
[sgLinkURL] [sgLinkText]a hyperlink is clickedtarget and visible text of the link
[OnLink.Source] .Start .End .Text .URLa hyperlink is clicked in the OnLink subroutine's name: 0 = left / 1 = right button, character range, text, target. Without an OnLink subroutine the link opens in the browser.
[sgFontList]sgEditorGetFontListall font names, one per line

Word, RTF and page view

Word documents. sgEditorLoadFile, sgEditorLoadFileDialog, sgEditorSaveFile, sgEditorSaveFileDialog and sgEditorExportDocument read and write .docx. No Microsoft Word is needed.

The conversion keeps the following:

  • character and paragraph formatting, and styles;
  • multi-level lists;
  • hyperlinks;
  • tables, including merged cells, borders and shading;
  • pictures and text boxes;
  • footnotes and endnotes, which appear as notes at the end;
  • section breaks;
  • page size and margins;
  • header and footer text;
  • the document title.

RichEdit cannot show floating positions, columns, comments or tracked changes, so those are not kept.

RTF. The paper size and margins stored in an .rtf are read on loading and written on saving.

Page view. sgEditorPageView "Rectangle1" "On" shows the document like Word's Print Layout: a white sheet of the real paper width on a grey desk, with the text inside the page margins. The margins come from the page setup, from the loaded document, or from sgEditorPageSetupDialog. New documents use Word's 1-inch margins.

Command index

CommandGroupPurpose
sgEditorOpenOpen/CloseOpen and configure the Rich Edit control.
sgEditorCloseOpen/CloseClose the text control window.
sgEditorSetFocusOpen/CloseSet focus to the editor.
sgEditorReAlignOpen/CloseRealign the editor.
sgEditorRedrawOpen/CloseRedraw the editor.
sgEditorRichEditVersionOpen/CloseGet Rich Edit version.
sgEditorPageViewSettingsShow the document as a page, like Word's Print Layout.
sgEditorSetBackgroundSettingsGet or set the editor background color.
sgEditorBiDiModeSettingsSet bidirectional text mode.
sgEditorHideSelectionSettingsSet selection visibility on focus loss.
sgEditorPlainTextSettingsSet plain/rich text mode.
sgEditorWordWrapSettingsSet word wrapping.
sgEditorWriteModeSettingsSet write mode.
sgEditorZoomSettingsGet or set the zoom factor.
sgEditorHeaderFooterSettingsSet the page header and footer used for printing and PDF.
sgEditorFontDialogTool MenuDisplay the Windows font dialog.
sgEditorParagraphDialogTool MenuDisplay paragraph formatting dialog.
sgEditorInsertObjectDialogTool MenuInsert an OLE object.
sgEditorPageSetupDialogTool MenuDisplay page setup dialog.
sgEditorPrinterSetupDialogTool MenuDisplay printer setup.
sgEditorPrintDialogTool MenuPrint the current document.
sgEditorPrintPreviewTool MenuShow the print preview window.
sgEditorFindReplaceDialogTool MenuShow the Find or Replace dialog.
sgEditorSpellOptionDialogTool MenuDisplay spell-check options.
sgEditorNewWordFileFileStart a new, empty Word document.
sgEditorLoadFileFileLoad a Word (.docx), RTF or text file.
sgEditorSaveFileFileSave the document as Word (.docx), RTF, text, HTML, Markdown or PDF.
sgEditorLoadFileDialogFileLoad a Word (.docx), RTF or text file.
sgEditorSaveFileDialogFileSave the current document.
sgEditorExportToPDFFileExport the document to PDF.
sgEditorExportDocumentFileExport the document as Word (.docx), HTML, Markdown, text or RTF.
sgEditorClipboardEditPerform clipboard actions.
sgEditorUndoEditUndo/redo editor operations.
sgEditorClearEditDelete the complete text.
sgEditorFindTextEditSearch for text in the document.
sgEditorReplaceTextEditFind and replace text.
sgEditorCheckStateEditCheck editor state or word count.
sgEditorModifiedStateEditGet modified state.
sgEditorProtectTextEditProtect or unprotect the selected text.
sgEditorSetTextText & LinesSet document text.
sgEditorGetTextText & LinesGet document text.
sgEditorGetTextLengthText & LinesGet document character count.
sgEditorAddLineText & LinesAdd a line at a specified line number.
sgEditorDeleteLineText & LinesDelete a specified line.
sgEditorGetLineText & LinesGet a line of text.
sgEditorGetLineFromCharText & LinesGet line number from character position.
sgEditorGetTotalLinesText & LinesGet total number of lines.
sgEditorSelStartSelectionGet or set selection start.
sgEditorSelLengthSelectionGet or set selection length.
sgEditorSelTextSelectionGet or set selected text.
sgEditorGetFontNameFontGet the font name.
sgEditorSetFontNameFontSet font name.
sgEditorGetFontSizeFontGet the font size.
sgEditorSetFontSizeFontSet font size.
sgEditorGetFontStyleFontGet the font style.
sgEditorSetFontStyleFontSet font style.
sgEditorTextColorFontGet or set text color.
sgEditorHighlightFontGet or set the text highlight (background) color.
sgEditorSetScriptFontSet superscript or subscript.
sgEditorGetFontListFontFill a VisualNEO ListBox/ComboBox with font names.
sgEditorGetAlignmentParagraphGet paragraph alignment.
sgEditorSetAlignmentParagraphSet paragraph alignment.
sgEditorFirstIndentParagraphGet or set first-line indentation.
sgEditorLeftIndentParagraphGet or set left indentation.
sgEditorRightIndentParagraphGet or set right indentation.
sgEditorLineSpacingParagraphGet or set line spacing.
sgEditorGetNumberingParagraphGet paragraph numbering style.
sgEditorSetNumberingParagraphSet bullets or numbering.
sgEditorInsertImageInsertInsert an image.
sgEditorInsertTableInsertInsert a table.
sgEditorInsertSpecialInsertInsert a page break or special character.
sgEditorLinkInsertCreate, edit or remove a hyperlink.
sgEditorSpellCheckSpell CheckRun spell checking.
sgEditorSpellSuggestSpell CheckSuggest spelling corrections.

Open/Close

Attach the editor to a Rectangle object, and hide or free it again.

sgEditorOpen

ID 33

Open and configure the Rich Edit control.

sgEditorOpen "Rectangle" "Variable" "OnFormat" "Border" "Toolbar" "BackgroundColor" "TextColor" "MeasurementUnits" "OnLink" "Ruler"
ParameterTypeMeaning
RectangleRectangle objectRectangle object to attach the Rich Edit control to
VariablevariableVariable linked to the editor text
[VariableName]
OnFormatsubroutineSubroutine to run on format change
Bordertext (option)Border
  • None
  • Single
Toolbartext (option)Show formatting toolbar
  • True
  • False
BackgroundColorcolourBackground color
R,G,B · #RRGGBB · clName · number
TextColorcolourText color
R,G,B · #RRGGBB · clName · number
MeasurementUnitstext (option)Measurement units
  • Pixels
  • Inches
  • Centimeters
  • Points
OnLinksubroutineSubroutine to run when a link is clicked
Rulertext (option)Show ruler
  • True
  • False

The object must be a Rectangle. OnFormat receives [sgFontName] [sgFontSize] [sgFontStyle] [sgAlignment] [sgSelStart] [sgSelLength]; OnLink receives [sgLinkURL].

Example
sgEditorOpen "Rectangle1" "[DocText]" "OnFormatChange" "Single" "True" "" "" "Centimeters" "OnLinkClick" "True"

sgEditorClose

ID 7

Close the text control window.

sgEditorClose "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Close mode
  • Hide hide the editor; its document is kept for the next sgEditorOpen
  • Free destroy the editor and its document

Hide keeps the document for a later sgEditorOpen; Free releases the editor.

Example
sgEditorClose "Rectangle1" "Hide"

sgEditorSetFocus

ID 48

Set focus to the editor.

sgEditorSetFocus "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorSetFocus "Rectangle1"

sgEditorReAlign

ID 39

Realign the editor.

sgEditorReAlign "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorReAlign "Rectangle1"

sgEditorRedraw

ID 40

Redraw the editor.

sgEditorRedraw "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorRedraw "Rectangle1"

sgEditorRichEditVersion

ID 41

Get Rich Edit version.

sgEditorRichEditVersion "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorRichEditVersion "Rectangle1" "[Result]"

Settings

Page view, colours, reading direction, wrapping, read-only mode, zoom, header and footer.

sgEditorPageView

ID 74

Show the document as a page, like Word's Print Layout.

sgEditorPageView "Rectangle" "Mode" "DeskColor"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Modetext (option)Page view
  • On show the page sheet
  • Off normal editor view
  • Toggle switch between the two
  • FitWidth page view, zoomed so the sheet width fits
DeskColorcolourDesk colour around the page (blank = grey)
R,G,B · #RRGGBB · clName · number

The sheet has the paper size and margins of the page setup (a loaded .docx or .rtf brings its own). FitWidth also zooms so the whole sheet width is visible. Blank desk colour = Word grey.

Example
sgEditorPageView "Rectangle1" "FitWidth" ""

sgEditorSetBackground

ID 2

Get or set the editor background color.

sgEditorSetBackground "Rectangle" "Color" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
ColorcolourBackground color (-1 = read current)
R,G,B · #RRGGBB · clName · number
VariablevariableVariable to receive the color (when Color is -1)
[VariableName]

Use -1 as Color to read the current background color into the variable.

Example
sgEditorSetBackground "Rectangle1" "255,253,240" ""

sgEditorBiDiMode

ID 3

Set bidirectional text mode.

sgEditorBiDiMode "Rectangle" "BiDiMode"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
BiDiModetext (option)Bidirectional mode
  • LeftToRight
  • RightToLeft
  • Auto each paragraph takes its direction from its own text

RightToLeft / LeftToRight set every paragraph; Auto picks the direction per paragraph from its text.

Example
sgEditorBiDiMode "Rectangle1" "LeftToRight"

sgEditorHideSelection

ID 24

Set selection visibility on focus loss.

sgEditorHideSelection "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Hide selection when the editor loses focus
  • True
  • False
Example
sgEditorHideSelection "Rectangle1" "True"

sgEditorPlainText

ID 36

Set plain/rich text mode.

sgEditorPlainText "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Plain text mode
  • True
  • False
Example
sgEditorPlainText "Rectangle1" "True"

sgEditorWordWrap

ID 59

Set word wrapping.

sgEditorWordWrap "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Word wrap
  • True
  • False
Example
sgEditorWordWrap "Rectangle1" "True"

sgEditorWriteMode

ID 60

Set write mode.

sgEditorWriteMode "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Write mode
  • EditMode the user can edit
  • ReadOnly the user cannot change the text
  • EnableEditProtected protected text may be changed
  • DisableEditProtected protected text is locked again

EnableEditProtected lets the user change protected text; DisableEditProtected blocks it again.

Example
sgEditorWriteMode "Rectangle1" "EditMode"

sgEditorZoom

ID 65

Get or set the zoom factor.

sgEditorZoom "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the zoom percent
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied. Percent, 100 = normal.

Example
SetVar "[Zoom]" "125"
sgEditorZoom "Rectangle1" "[Zoom]"

sgEditorHeaderFooter

ID 70

Set the page header and footer used for printing and PDF.

sgEditorHeaderFooter "Rectangle" "Header" "Footer"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
HeadertextHeader
FootertextFooter

Use left|center|right; tokens {page} {pages} {date} {time} {title}.

Example
sgEditorHeaderFooter "Rectangle1" "LIS Software Lab||{date}" "|Page {page} of {pages}|"

Tool Menu

Built-in dialogs: font, paragraph, page setup, printing, preview, find/replace, spelling options.

sgEditorFontDialog

ID 12

Display the Windows font dialog.

sgEditorFontDialog "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorFontDialog "Rectangle1"

sgEditorParagraphDialog

ID 35

Display paragraph formatting dialog.

sgEditorParagraphDialog "Rectangle" "Language" "MeasurementUnits"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
LanguagetextDialog language (English or path of an .ini file)
MeasurementUnitstext (option)Measurement units
  • Pixels
  • Inches
  • Centimeters
  • Points
Example
sgEditorParagraphDialog "Rectangle1" "English" "Centimeters"

sgEditorInsertObjectDialog

ID 26

Insert an OLE object.

sgEditorInsertObjectDialog "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable (in: file to embed or blank; out: object type)
[VariableName]

If the variable holds a file name that file is embedded without a dialog. Afterwards it receives the object type (blank = cancelled).

Example
sgEditorInsertObjectDialog "Rectangle1" "[Result]"

sgEditorPageSetupDialog

ID 34

Display page setup dialog.

sgEditorPageSetupDialog "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorPageSetupDialog "Rectangle1"

sgEditorPrinterSetupDialog

ID 38

Display printer setup.

sgEditorPrinterSetupDialog "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorPrinterSetupDialog "Rectangle1"

sgEditorPrintDialog

ID 37

Print the current document.

sgEditorPrintDialog "Rectangle" "Dialog" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Dialogtext (option)Show print dialog
  • Default show the Windows print dialog
  • Yes show the print dialog
  • No print straight to the printer
OptionstextOptions, e.g. Title=Report;Copies=2;Printer=name;Pages=1-3
Example
sgEditorPrintDialog "Rectangle1" "No" "Title=Report;Copies=2;Pages=1-3"

sgEditorPrintPreview

ID 69

Show the print preview window.

sgEditorPrintPreview "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorPrintPreview "Rectangle1"

sgEditorFindReplaceDialog

ID 66

Show the Find or Replace dialog.

sgEditorFindReplaceDialog "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Dialog
  • Find
  • Replace
Example
sgEditorFindReplaceDialog "Rectangle1" "Find"

sgEditorSpellOptionDialog

ID 55

Display spell-check options.

sgEditorSpellOptionDialog "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorSpellOptionDialog "Rectangle1"

File

New Word documents, loading and saving (.docx, .rtf, .txt, .html, .md, .pdf) and exports.

sgEditorNewWordFile

ID 73

Start a new, empty Word document.

sgEditorNewWordFile "Rectangle" "FileName" "PageSize" "PrintOrientation"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FileNamefile nameNew Word file (blank = choose later)
PageSizetext (option)Page size
  • A4
  • Letter
  • Legal
  • A5
  • A3
  • B5
PrintOrientationtext (option)Orientation
  • Portrait
  • Landscape

Clears the text and resets page setup, header and footer. With a file name the empty .docx is created at once and becomes the current file for sgEditorSaveFile.

Example
sgEditorNewWordFile "Rectangle1" "[PubDir]Letter.docx" "A4" "Portrait"

sgEditorLoadFile

ID 71

Load a Word (.docx), RTF or text file.

sgEditorLoadFile "Rectangle" "FileName" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FileNamefile nameDocument to load
VariablevariableVariable to receive True or False
[VariableName]

The format is detected from the file content. The variable receives True or False; [LastError] holds the reason of a failure. Blank file name = Open dialog.

Example
sgEditorLoadFile "Rectangle1" "[PubDir]Report.docx" "[Loaded]"
If "[Loaded]" "=" "False"
  AlertBox "Cannot open" "[LastError]"
EndIf

sgEditorSaveFile

ID 72

Save the document as Word (.docx), RTF, text, HTML, Markdown or PDF.

sgEditorSaveFile "Rectangle" "FileName" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FileNamefile nameFile to save (blank = current file)
VariablevariableVariable to receive True or False
[VariableName]

The extension picks the format. Blank file name = the file last loaded or saved (Save dialog when there is none).

Example
sgEditorSaveFile "Rectangle1" "" "[Saved]"

sgEditorLoadFileDialog

ID 31

Load a Word (.docx), RTF or text file.

sgEditorLoadFileDialog "Rectangle" "FileName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FileNamefile nameFile to load

Leave the file name blank to show the Open dialog at run time.

Example
sgEditorLoadFileDialog "Rectangle1" ""

sgEditorSaveFileDialog

ID 43

Save the current document.

sgEditorSaveFileDialog "Rectangle" "FileName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FileNamefile nameFile to save

Leave the file name blank to show the Save dialog at run time. The extension picks the format: .docx, .rtf, .txt, .html, .md or .pdf.

Example
sgEditorSaveFileDialog "Rectangle1" "[PubDir]Copy.rtf"

sgEditorExportToPDF

ID 9

Export the document to PDF.

sgEditorExportToPDF "Rectangle" "Engine" "Resolution" "PageMargins" "PageSize" "PrintOrientation" "PDFFileName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Enginetext (option)PDF engine (Vector = Microsoft Print to PDF, Image = rendered pages)
  • Auto
  • Vector
  • Image
Resolutiontext (option)Resolution of the Image engine (dpi)
  • 150
  • 200
  • 300
PageMarginstextMargins in mm: all or left,top,right,bottom (blank = page setup)
PageSizetext (option)Page size (blank = page setup)
  • "" blank = keep the page setup value
  • A4
  • A5
  • A3
  • B5
  • Letter
  • Legal
PrintOrientationtext (option)Orientation (blank = page setup)
  • "" blank = keep the page setup value
  • Portrait
  • Landscape
PDFFileNamefile namePDF file to create

Header/footer from sgEditorHeaderFooter are included. Auto uses Vector when the PDF printer is installed.

Example
sgEditorExportToPDF "Rectangle1" "Auto" "150" "" "A4" "Portrait" "[PubDir]Report.pdf"

sgEditorExportDocument

ID 68

Export the document as Word (.docx), HTML, Markdown, text or RTF.

sgEditorExportDocument "Rectangle" "Format" "FileName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Formattext (option)Format
  • DOCX Word document
  • HTML
  • Markdown
  • Text
  • RTF
FileNamefile nameFile to create

Blank format = taken from the file extension. Exporting does not change the current file name.

Example
sgEditorExportDocument "Rectangle1" "HTML" "[PubDir]Report.html"

Edit

Clipboard, undo, searching and replacing, document state and protected text.

sgEditorClipboard

ID 6

Perform clipboard actions.

sgEditorClipboard "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Clipboard operation
  • Cut
  • Copy
  • Paste
  • SelectAll
  • Clear
Example
sgEditorClipboard "Rectangle1" "Cut"

sgEditorUndo

ID 58

Undo/redo editor operations.

sgEditorUndo "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Operation
  • Undo
  • Redo
Example
sgEditorUndo "Rectangle1" "Undo"

sgEditorClear

ID 5

Delete the complete text.

sgEditorClear "Rectangle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Example
sgEditorClear "Rectangle1"

sgEditorFindText

ID 10

Search for text in the document.

sgEditorFindText "Rectangle" "FoundVariable" "FindString" "Start" "Highlight" "MatchCase" "WholeWord"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FoundVariablevariableVariable to receive the found position (-1 = not found)
[VariableName]
FindStringtextText to find
StartnumberStart position (blank = after the selection)
Highlighttext (option)Select the found text
  • True
  • False
MatchCasetext (option)Match case
  • True
  • False
WholeWordtext (option)Whole word only
  • True
  • False
Example
sgEditorFindText "Rectangle1" "[Pos]" "library" "" "True" "False" "True"

sgEditorReplaceText

ID 67

Find and replace text.

sgEditorReplaceText "Rectangle" "FindString" "ReplaceWith" "Options" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FindStringtextFind
ReplaceWithtextReplace with
Optionstext (option)Options
  • All
  • All,MatchCase
  • All,WholeWord
  • All,MatchCase,WholeWord
  • Next
VariablevariableVariable to receive the number of replacements
[VariableName]

Options: All (else only the next match), MatchCase, WholeWord.

Example
sgEditorReplaceText "Rectangle1" "colour" "color" "All,WholeWord" "[Count]"

sgEditorCheckState

ID 4

Check editor state or word count.

sgEditorCheckState "Rectangle" "CheckThis" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
CheckThistext (option)State to check
  • CanUndo True if Undo is possible
  • CanRedo True if Redo is possible
  • CanPaste True if the clipboard holds text or a picture
  • WordCount number of words in the document
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorCheckState "Rectangle1" "WordCount" "[Words]"

sgEditorModifiedState

ID 32

Get modified state.

sgEditorModifiedState "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable for the modified flag
[VariableName]

If the variable holds TRUE or FALSE the flag is set; otherwise the current state is read into it.

Example
SetVar "[Changed]" ""
sgEditorModifiedState "Rectangle1" "[Changed]"
If "[Changed]" "=" "True"
  sgEditorSaveFile "Rectangle1" "" ""
EndIf

sgEditorProtectText

ID 64

Protect or unprotect the selected text.

sgEditorProtectText "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Protect the selection
  • True
  • False
  • Toggle

Protected text cannot be changed by the user.

Example
sgEditorProtectText "Rectangle1" "True"

Text & Lines

Put text into the editor, read it back, and work with lines.

sgEditorSetText

ID 53

Set document text.

sgEditorSetText "Rectangle" "Text"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
TexttextText to place in the editor

Text beginning with {\rtf is loaded as rich text.

Example
sgEditorSetText "Rectangle1" "Dear reader,"

sgEditorGetText

ID 21

Get document text.

sgEditorGetText "Rectangle" "Options" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Text format
  • Text plain text
  • RTF the whole document as RTF
  • HTML an HTML page
  • Markdown Markdown text
  • SelectedText only the selected text
  • WordAtCursor the word at the caret
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetText "Rectangle1" "RTF" "[DocRtf]"

sgEditorGetTextLength

ID 22

Get document character count.

sgEditorGetTextLength "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetTextLength "Rectangle1" "[Result]"

sgEditorAddLine

ID 1

Add a line at a specified line number.

sgEditorAddLine "Rectangle" "LineNumber" "Text"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
LineNumbernumberLine number to insert at (-1 = append)
TexttextText of the new line
Example
sgEditorAddLine "Rectangle1" "-1" "A new last line"

sgEditorDeleteLine

ID 8

Delete a specified line.

sgEditorDeleteLine "Rectangle" "LineNumber"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
LineNumbernumberLine number to delete (0-based)
Example
sgEditorDeleteLine "Rectangle1" "1"

sgEditorGetLine

ID 18

Get a line of text.

sgEditorGetLine "Rectangle" "Line" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
LinenumberLine number (0-based)
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetLine "Rectangle1" "1" "[Result]"

sgEditorGetLineFromChar

ID 19

Get line number from character position.

sgEditorGetLineFromChar "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the line number at the caret
[VariableName]
Example
sgEditorGetLineFromChar "Rectangle1" "[Result]"

sgEditorGetTotalLines

ID 23

Get total number of lines.

sgEditorGetTotalLines "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetTotalLines "Rectangle1" "[Result]"

Selection

Read or change the selection.

sgEditorSelStart

ID 45

Get or set selection start.

sgEditorSelStart "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the selection start
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied.

Example
SetVar "[Start]" "0"
sgEditorSelStart "Rectangle1" "[Start]"

sgEditorSelLength

ID 44

Get or set selection length.

sgEditorSelLength "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the selection length
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied.

Example
sgEditorSelLength "Rectangle1" "[Result]"

sgEditorSelText

ID 46

Get or set selected text.

sgEditorSelText "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the selected text
[VariableName]

An empty variable receives the selected text; otherwise its text replaces the selection.

Example
SetVar "[Sel]" ""
sgEditorSelText "Rectangle1" "[Sel]"
. [Sel] now holds the selected text

Font

Character formatting of the selection (or of the text typed next).

sgEditorGetFontName

ID 15

Get the font name.

sgEditorGetFontName "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetFontName "Rectangle1" "[Result]"

sgEditorSetFontName

ID 49

Set font name.

sgEditorSetFontName "Rectangle" "FontName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FontNamefont nameFont name
Example
sgEditorSetFontName "Rectangle1" "Nirmala UI"

sgEditorGetFontSize

ID 16

Get the font size.

sgEditorGetFontSize "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetFontSize "Rectangle1" "[Result]"

sgEditorSetFontSize

ID 50

Set font size.

sgEditorSetFontSize "Rectangle" "FontSize"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FontSizenumberFont size
Example
sgEditorSetFontSize "Rectangle1" "14"

sgEditorGetFontStyle

ID 17

Get the font style.

sgEditorGetFontStyle "Rectangle" "FontStyle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FontStyletext (option)Style to test (blank = list all styles)
  • "" blank = keep the page setup value
  • Bold
  • Italic
  • Underline
  • Strikeout
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetFontStyle "Rectangle1" "Bold" "[Result]"

sgEditorSetFontStyle

ID 51

Set font style.

sgEditorSetFontStyle "Rectangle" "FontStyle"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
FontStyletext (option)Font style
  • None
  • Bold
  • Italic
  • Underline
  • Strikeout
  • Bold Italic
  • ToggleBold
  • ToggleItalic
  • ToggleUnderline
  • ToggleStrikeout
  • NoBold
  • NoItalic
  • NoUnderline
  • NoStrikeout

Bold/Italic/... add a style, ToggleX switches it, NoX removes it, None clears all.

Example
sgEditorSetFontStyle "Rectangle1" "ToggleBold"

sgEditorTextColor

ID 57

Get or set text color.

sgEditorTextColor "Rectangle" "Color" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
ColorcolourText color (-1 = read current)
R,G,B · #RRGGBB · clName · number
VariablevariableVariable to receive the color (when Color is -1)
[VariableName]

Use -1 as Color to read the current text color into the variable.

Example
sgEditorTextColor "Rectangle1" "192,0,0" ""
sgEditorTextColor "Rectangle1" "-1" "[CurrentColor]"

sgEditorHighlight

ID 61

Get or set the text highlight (background) color.

sgEditorHighlight "Rectangle" "Color" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
ColorcolourHighlight color (None = remove, -1 = read current)
R,G,B · #RRGGBB · clName · number
VariablevariableVariable to receive the color (when Color is -1)
[VariableName]

None removes the highlight; -1 reads the current color into the variable.

Example
sgEditorHighlight "Rectangle1" "#FFFF00" ""

sgEditorSetScript

ID 62

Set superscript or subscript.

sgEditorSetScript "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Script
  • Normal
  • Superscript
  • Subscript
  • ToggleSuperscript
  • ToggleSubscript
Example
sgEditorSetScript "Rectangle1" "Normal"

sgEditorGetFontList

ID 14

Fill a VisualNEO ListBox/ComboBox with font names.

sgEditorGetFontList "Rectangle" "ListBox"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
ListBoxobject nameListBox or ComboBox object to fill
Example
sgEditorGetFontList "Rectangle1" "FontCombo"

Paragraph

Alignment, indents, line spacing, bullets and numbering of the selected paragraphs.

sgEditorGetAlignment

ID 13

Get paragraph alignment.

sgEditorGetAlignment "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetAlignment "Rectangle1" "[Result]"

sgEditorSetAlignment

ID 47

Set paragraph alignment.

sgEditorSetAlignment "Rectangle" "Alignment"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Alignmenttext (option)Alignment
  • Left
  • Center
  • Right
  • Justify
Example
sgEditorSetAlignment "Rectangle1" "Left"

sgEditorFirstIndent

ID 11

Get or set first-line indentation.

sgEditorFirstIndent "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the first-line indent
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied.

Example
SetVar "[Indent]" "1.25"
sgEditorFirstIndent "Rectangle1" "[Indent]"

sgEditorLeftIndent

ID 28

Get or set left indentation.

sgEditorLeftIndent "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the left indent
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied.

Example
SetVar "[Indent]" "-1"
sgEditorLeftIndent "Rectangle1" "[Indent]"
. [Indent] now holds the current left indent

sgEditorRightIndent

ID 42

Get or set right indentation.

sgEditorRightIndent "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the right indent
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied.

Example
sgEditorRightIndent "Rectangle1" "[Result]"

sgEditorLineSpacing

ID 29

Get or set line spacing.

sgEditorLineSpacing "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable holding the line spacing
[VariableName]

Put -1 in the variable to read the current value into it; any other value is applied. Values: 1, 1.5, 2 ...

Example
SetVar "[Spacing]" "1.5"
sgEditorLineSpacing "Rectangle1" "[Spacing]"

sgEditorGetNumbering

ID 20

Get paragraph numbering style.

sgEditorGetNumbering "Rectangle" "Variable"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
VariablevariableVariable to receive the result
[VariableName]
Example
sgEditorGetNumbering "Rectangle1" "[Result]"

sgEditorSetNumbering

ID 52

Set bullets or numbering.

sgEditorSetNumbering "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Numbering (Type[,Period|Paren|Parens|Plain[,Start]])
  • None
  • Bullet
  • Arabic,Period,1 1. 2. 3. - type, style (Period, Paren, Parens, Plain), start
  • LowerLetter,Paren,1
  • UpperLetter,Period,1
  • LowerRoman,Period,1
  • UpperRoman,Period,1
  • ToggleBullet bullets on/off
  • Increase one list level deeper
  • Decrease one list level up

Increase / Decrease change the list level (indent).

Example
sgEditorSetNumbering "Rectangle1" "LowerRoman,Paren,1"

Insert

Pictures, tables, special characters, page breaks and hyperlinks.

sgEditorInsertImage

ID 25

Insert an image.

sgEditorInsertImage "Rectangle" "PictureName"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
PictureNamefile nameImage file (blank = let the user choose)
Example
sgEditorInsertImage "Rectangle1" "[PubDir]logo.png"

sgEditorInsertTable

ID 63

Insert a table.

sgEditorInsertTable "Rectangle" "Rows" "Columns" "ColumnWidth" "Borders"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
RowsnumberRows
ColumnsnumberColumns
ColumnWidthnumberColumn width (0 = fit page)
Borderstext (option)Cell borders
  • True
  • False

Column width is in the sgEditorOpen measurement units; 0 divides the page width equally.

Example
sgEditorInsertTable "Rectangle1" "3" "4" "0" "True"

sgEditorInsertSpecial

ID 27

Insert a page break or special character.

sgEditorInsertSpecial "Rectangle" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
Optionstext (option)Item to insert
  • PageBreak start a new page when printing
  • LineBreak
  • Tab
  • NonBreakingSpace
  • NonBreakingHyphen
  • SoftHyphen
  • EnDash
  • EmDash
  • Bullet
  • Ellipsis
  • Copyright
  • Registered
  • Trademark
  • Section
  • Pilcrow
  • Degree
  • Euro
  • Rupee
  • Date today's date
  • Time
  • DateTime
  • U+2605 any Unicode character by its code

U+XXXX inserts any Unicode character; other text is inserted as typed.

Example
sgEditorInsertSpecial "Rectangle1" "PageBreak"
sgEditorInsertSpecial "Rectangle1" "U+20B9"

Spell Check

Windows spell checker: dialog, live underlining and suggestions.

sgEditorSpellCheck

ID 54

Run spell checking.

sgEditorSpellCheck "Rectangle" "Language" "Options"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
LanguagetextDictionary language, e.g. en-US or English (blank = Windows default)
Optionstext (option)Mode
  • Dialog check the document with the spelling dialog
  • LiveOn underline misspelt words while typing
  • LiveOff stop live checking

Uses the Windows spell checker (Windows 8+). Dialog checks the document; LiveOn underlines errors while typing.

Example
sgEditorSpellCheck "Rectangle1" "en-IN" "LiveOn"

sgEditorSpellSuggest

ID 56

Suggest spelling corrections.

sgEditorSpellSuggest "Rectangle" "CheckThisWord" "SuggestWords"
ParameterTypeMeaning
RectangleRectangle objectRectangle object hosting the Rich Edit control
CheckThisWordtextWord to check (blank = word at the caret)
SuggestWordsvariableVariable to receive the suggestions
[VariableName]

The variable receives -1 if the word is correct, otherwise the suggestions separated by | (empty = none).

Example
sgEditorSpellSuggest "Rectangle1" "recieve" "[Words]"
. [Words] = receive|relieve|...

Troubleshooting

ProblemWhat to do
"Invalid pointer operation" or an access violation when VisualNEO closesInstall the plug-in from a copied location, not from Delphi's build folder. Close VisualNEO before replacing the .nbp. Keep only one copy of sgNeoWordEditor in Plug-In Installer.
An older publication reads [edFontName], [edLinkURL] and so onFrom version 2.2 these variables start with sg: [sgFontName], [sgFontSize], [sgFontStyle], [sgAlignment], [sgSelStart], [sgSelLength], [sgLinkURL], [sgLinkText], [sgFontList]. Rename them in the publication.
"An object named ... does not exist"Check the Rectangle name in the command's first parameter.
A .docx does not openRead [LastError]. Old .doc files and password-protected documents must be saved as a normal .docx in Word first.
No spelling suggestionsInstall the language in Windows (Settings › Time & language › Language), then pass it to sgEditorSpellCheck, for example en-IN.
PDF text cannot be selectedThe Image engine was used. Install Microsoft Print to PDF (Windows features) or pass Vector.