Applies to HTML Viewer, IE Browser publications. HEScript scripts are especially designed to control the publication's behavior and to communicate with the environment (runtime module, Windows...). You have a lot of internal functions that can be called from within the HEScript script functions/procedures.  | Notes: - More functions may be added with the next runtime modules releases. Please check the www.htmlexe.com website for the latest versions.
- If you have ideas about functions, feedback or bugs to report, please go to our forums and post them. You can also contact the technical support.
- A lot of internal functions are not listed here at this time (but may be used in system HTML pages for instance). Please ignore them or contact us for more information.
- Please have a look at the samples, articles and the knowledge base at www.htmlexe.com
|
List and descriptions of internal script functions Interface related:
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| MessageBox | Displays a message box (similar to the Windows API MessageBox) function MessageBox(const Text: String; const Title: String; const Flags: Integer): Integer; | - Text: the contents of the message box.
- Title: the title of the message box.
- Flags: set of bit flags that determine the contents and behavior of the box. More information here.
May be MB_OK, MB_OKCANCEL, MB_YESNOCANCEL, MB_YESNO, .... plus MB_ICONSTOP, MB_ICONINFORMATION, MB_ICONWARNING... - Result (integer): may be IDOK, IDCANCEL, ..., IDYES, IDNO depending on the button selected by the user.
| | MessageDlg | Displays a skinnable message box. function MessageDlg (const Message : string; const Title: String; DialogType : TMsgDlgType; Buttons : TMsgDlgButtons) : Integer; | - Message: the contents of the message box.
- Title: the title of the message box.
- DialogType: can be one of the following enumerated values: mtWarning, mtError, mtInformation, mtConfirmation or mtCustom.
- Buttons: set of flags between [ ] that define the buttons of the message box: mbYes, mbNo, mbOK, mbCancel. Examples: [mbOK, mbCancel] or [mbOK]
- Result (integer): may be IDOK, IDCANCEL, ..., IDYES, IDNO depending on the button selected by the user.
Example: MessageDlg("My message", "My title", mtInformation, [mbOK]); More details available here Note: this function should not be called in the initialization event nor when the publication exits. | | SetUIProp | Sets the value of the specified property of a control whose name is given by id. For internal use. procedure SetUIProp(const id, propname, propval: String); | - id: name of the control.
- propname: name of the property.
- propval: new value to give (always string).
| | GetUIProp | Gets the value of the specified property of a control whose name is given by id. For internal use. function GetUIProp(const id, propname: String): String; | - id: name of the control.
- propname: name of the property.
- result: the value of the property (in string format). If the control is not found, an error may occur.
| | ChangeStatusBar | Sets the text of the status bar. procedure ChangeStatusBar(const Text: String; Reset: Boolean); | - Text: new text to show in the status bar.
- Reset: if true, the text will be set as the default text.
| | ShowLeftPanel | Opens/hides the specified navigation panel. procedure ShowLeftPanel(const id: Integer; OpenIt: Boolean); | - Id: index of the panel you want to show.
- OpenIt: if false, the navigation panel is hidden (whatever the value of Id). Otherwise it is displayed.
Possible ID values: - 1: Search.
- 2: TOC (Table of Contents)
- 3: Favorites
- 4: Favorite Manager
IMPORTANT: the navigation panel must have been enabled in HTML Executable! Otherwise you will get problems. | | GetLeftPanel | Returns the index of the current navigation panel. function GetLeftPanel: Integer | - Result: index of the panel currently displayed.
See possible values above. Returns 0 if no panel is displayed. | | ShowAboutBox | Shows the About box. procedure ShowAboutBox; | |
Navigation related:
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| GoToPage | Displays (or executes) the specified URL. procedure GoToPage(const Name, Window: String); | - Name: partial or full URL to display. This can be a single HTML page, a full URL (you can use the ghe://heserver/ internal protocol, or standard protocols
like http, ftp, etc...) or even a hescript:// command. - Window: do not use at this time (internal use only). Leave blank "".
| | UseMapID | Displays the HTML page whose map ID corresponds to ID. procedure UseMapID(const ID: Integer); | | | ReloadPage | Reloads the entire page (refresh). procedure ReloadPage; | | | GetCurrentHTMLPagePath | Returns the full URL to the current HTML page displayed. function GetCurrentHTMLPagePath: String; | - Result: the full URL to the current displayed page.
| | ExitPublication | Terminates the publication. procedure ExitPublication; | | | NavigateCommand | Executes a common navigation command. procedure NavigateCommand(const Command: Integer); | - Command: one of the following values:
- 0: return to the previous page (back).
- 1: move to the next page (forward).
- 2: go to the top of the page.
- 3: copy selected text to clipboard.
- 4: select the entire page.
- 5: paste text from clipboard (IE only).
- 6: page zoom in (IE only).
- 7: page zoom out (IE only).
- 8: show Internet Explorer options (IE only) like if you select "Tools > Internet Options" in IE.
| | SeqGoPrevious | Shows the previous page in a Browse Sequence procedure SeqGoPrevious; | | | SeqGoNext | Shows the next page in a Browse Sequence procedure SeqGoNext; | | | ExecuteHTMLScript | Executes a script function in a HTML page (JavaScript, VBScript...). Only available for IE publications. procedure ExecuteHTMLScript(const CommandLine, Language: String); | - CommandLine: the script function you would like to call including its optional arguments.
- Language: the name of the script language this function is written into (JavaScript, VBScript...)
Example: to call this simple JavaScript function:
<script language="JavaScript">
<!--
function Say(what)
{
window.alert(what)
}
-->
</script>use this: ExecuteHTMLScript("Say('this is what I say')", "JavaScript"); |
Management related:
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| SetGlobalVar | Sets the value and properties of a global variable. procedure SetGlobalVar(const Name, Value: String; const IsStored: Boolean); | - Name: name of the global variable.
- Value: new value for the global variable.
- IsStored: indicates whether the global variable is a persistent one, i.e. it is stored in the publication's state data file and restored when the publication is run again.
Use global variables to store or exchange data between different scripts. | | GetGlobalVar | Gets the value of a global variable. function GetGlobalVar(const Name, DefaultIfNotFound: String): String; | - Name: name of the global variable.
- DefaultIfNotFound: what the function should return if the global variable is not found.
- Result: the value of the variable if it exists, otherwise the value of DefaultIfNotFound.
Publications use a lot of internal global variables. You can get a list of interesting ones here. | | SynchronizeGlobalVar | If several instances of a publication are running, call this function to force all global variables (only the persistent ones: see above) to get the same value as the ones of the publication who made the call. procedure SynchronizeGlobalVar; | Persistent global variables can be used to share data between several instances of a publication. | | GetString | Returns the value of a resource string. function GetString(const ID: String): String; | - ID: name of the resource string.
- Result: the value of the resource string, or blank if not found.
| | WriteRegStr | Writes a string entry in the Windows registry. procedure WriteRegStr(Root: Integer; Key,Ident,Value: String); | - Root: root key ID, see list below.
- Key: name of the subkey.
- Ident: name of the entry.
- Value: string value to be written.
List of root key IDs: 0: HKEY_CLASSES_ROOT 1: HKEY_CURRENT_CONFIG 2: HKEY_CURRENT_USER 3: HKEY_DYN_DATA 4: HKEY_LOCAL_MACHINE 5: HKEY_USERS | | WriteRegDW | Writes an integer entry in the Windows registry. procedure WriteRegDW(Root: Integer; Key,Ident: String; Value: Integer); | - Root: root key ID, see list above.
- Key: name of the subkey.
- Ident: name of the entry.
- Value: integer value to be written.
| | ReadRegStr | Reads the value of a string entry from the Windows registry. function ReadRegStr(Root: Integer; Key,Ident,Default: String): String; | - Root: root key ID, see list above.
- Key: name of the subkey.
- Ident: name of the entry.
- Default: default return value if the entry is not found.
- Result: the value of the string entry.
| | ReadRegDW | Reads the value of an integer entry from the Windows registry. function ReadRegDW(Root: Integer; Key,Ident: String; Default: Integer): Integer; | - Root: root key ID, see list above.
- Key: name of the subkey.
- Ident: name of the entry.
- Default: default return value if the entry is not found.
- Result: the value of the integer entry.
| | GetViewerSerial | Returns the unique ID of the runtime module used to run this publication. function GetViewerSerial: String; | |
HTML related:
Please note that some of these functions are only designed for HTML Viewer publications, as they try to compensate the lack of JavaScript support. If you work with IE Browser publications, then try to use JavaScript instead. | Function name | Description & prototype | Parameters, example, remarks |
|---|
| ShowHTMLBlockID | Provides an easy way to control the display of a block of HTML text. Typical blocks that can be controlled include <div>, <p>, <ul>, <form>, <table>, etc. The block tag must contain an ID= attribute to identify it.procedure ShowHTMLBlockID(const ID: String; Visible: Boolean); | - ID: ID of the HTML block.
- Visible: Setting Visible to False hides the block and setting it to True displays the block.
Works both in HTML Viewer and IE browser publications. | | GetFormFieldValue | Returns the value of a form field (when a form has been submitted, i.e. a Submit button was pressed). function GetFormFieldValue(const NameField: String; Default: String): String; | - NameField: name of the form field.
- Default: default value if the field is not found.
Be careful: this function will only work when a form has been submitted, so you should use only in special HTML page events like OnFormSubmit. Should be used only in HTML Viewer publications, but may work in IE browser publications too. | | GetFormContents | Returns the entire contents of a form which has been submitted. function GetFormContents: String; | Warning: it only works with HTML Viewer publications. Use it in special HTML page events like OnFormSubmit. | | SaveFormResultsToFile | Saves the form results to an external file (if a form has been submitted!). function SaveFormResultsToFile(const Filename: String): String; | - Filename: output filename (will be in text format).
- Result: returns the Filename value if the operation was successful.
Warning: it only works with HTML Viewer publications currently. Use it in special HTML page events like OnFormSubmit. | | SetFormControlValue | Sets the value of a form field, or a property of an ActiveX control (use of the PANEL tag). procedure SetFormControlValue(const ControlName, PropertyName, PropertyValue: String); | - Controlname: name of the control or form field. There is no need to indicate which form the field belongs to. However your controls should have unique names in a HTML page.
- PropertyName: which property should be set. Must be Text if the control is a form field.
- PropertyValue: the new value to give to the property.
This function works only in HTML Viewer publications! You can use this function at any time, it does not require a form to be submitted first contrary to the previous functions. | | GetFormControlValue | Gets the value of a form field, or a property of an ActiveX control (use of the PANEL tag). function GetFormControlValue(const ControlName, PropertyName, DefValue: String): String; | - Controlname: name of the control or form field. There is no need to indicate which form the field belongs to. However your controls should have unique names in a HTML page.
- PropertyName: the property whose value should be read. Must be Text if the control is a form field.
- DefValue: the value if the control is not found.
- Result: returns the value of the property in string format.
This function works only in HTML Viewer publications! | | CallFormControlMethod | Calls a method of an ActiveX control (use of the PANEL tag). Experimental use at this time! procedure CallFormControlMethod(const ControlName, MethodName, MethodParams: String); | - Controlname: name of the control.
- MethodName: name of the method to call.
- MethodParams: parameters to pass to the method (if any). Syntax: Param1|.....|ParamN (use the | character to separate them).
This function works only in HTML Viewer publications! | | ShowFindDialog | Displays the Find Text dialog (search in the current HTML page only) procedure ShowFindDialog(const FindText: String); | - FindText: default text to search for. Only used with HTML Viewer publications.
| | FindTextInPage | Searches through the HTML document for the string, S, returning True if the string is found. function FindTextInPage(const S: String; MatchCase, Reverse: boolean): boolean; | - S: the text you are looking for.
- MatchCase: If True, a case sensitive search is made.
- Reverse: If True, the search is made in the reverse direction.
The last remaining parameter is ignored in a IE browser publication. | | StartFullSearch | Launches a full text search in the entire publication. The Search engine must have been enabled! The search results are displayed in the navigation panel. procedure StartFullSearch(const Query: String; ScriptFormatName: String); | - Query: what you are looking for. You may use the logical operators AND, OR, NOT.
- ScriptFormatName: script of the search engine. Must be "search.hex".
| | PrintPages | Prints the current HTML page. procedure PrintPages(const FromPage, ToPage: Integer; ShowDialog: Boolean); | - Prints the current document starting with FromPage and ending with ToPage. Pages start at page 1.
To print the entire document, set ToPage to 9999. - ShowDialog: whether the print dialog is displayed or not.
These parameters are ignored in a IE browser publication. Use JavaScript instead. | | ShowPrintPreview | Displays the print preview window. procedure ShowPrintPreview(const FrameName: String); | - FrameName: if your document uses frame, specify which frame should be displayed in the print preview.
This parameter is ignored in a IE browser publication. | | StrToHTML | Generates the HTML code for the given string. function StrToHTML(const Str: String): String; | - Str: the string you want to convert to HTML.
| | PlayMediaFile | Plays a media file using the internal media player. procedure PlayMediaFile(const Source: String; Loop: Integer); | - Source: path to the media file to be played. It should an absolute path but without the protocol and the root, e.g. MyFolder\Media1.mid
- Loop: how many times the media should be played. Enter -1 for infinite.
The internal media player recognizes MIDI and WAV files. It uses the MCI functions of Windows. Only for HTML Viewer publications. | | StopMediaPlayer | Stops the media player if it is playing a media file. procedure StopMediaPlayer; | Only for HTML Viewer publications. |
Popup window related (only for IE Browser publications)
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| ShowPopup | Opens the specified URL in a new window. procedure ShowPopup(const Name, URL: String; Width, Height, Top, Left: Integer; IsModal, RedirectLinksToMain: Boolean); | - Name: name of your popup window.
- URL: url to the page that should be displayed. It can be a virtual path to a compiled page or a full URL.
- Width, Height: width and height of the popup window (in pixels).
- Left, Top: x and y screen coordinates of the top-left corner (in pixels).
- IsModal: always set the value to false.
- RedirectLinksToMain: whether you want the popup window to redirect all hyperlinks to the main window (when a user clicks a link, the page is displayed in the main window). Could be useful for website contents.
To create a screen-centered popup, set both Left and Top to -1. Sample available here | | ClosePopup | Closes a popup window. procedure ClosePopup(const Name: String); | - Name: name of the popup window that should be closed.
| | CloseAllPopups | Closes all popup windows that are visible. procedure CloseAllPopups; | |
External Programs/Files
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| OpenFile | Opens an external document or program file. function OpenFile(const Filename, Parameters: String; State: Integer): Integer; | - Filename: full path to the file you want to open or run.
- Parameters: optional command line parameters.
- State: window state. May be SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_HIDE...
- Result: successful if greater than 31.
For executable files, you may also use RunAProgram. | | UnpackTemporaryResource | Extracts a file from the publication's data (it must have been compiled) to a temporary file and returns the path to this file. The file is normally removed when the publication closes. function UnpackTemporaryResource(const SourceName: String): String; | - SourceName: virtual path to the file you want to extract from the publication's data.
- Result: full path to the extracted temporary file on the user hard disk.
You can use this function to extract and run special files that cannot be handled by the publication, such as video, executable, etc... Useful with OpenFile. | | ExportAFile | Same as the previous function, except that it will display a Save As dialog box, and the file is not temporary. Acts like when you download a file from the Internet. function ExportAFile(const SourceName: String; PromptTitle, DefFilename: String): String; | - SourceName: virtual path to the file you want to extract from the publication's data.
- PromptTitle: the title of the Save As dialog box.
- DefFilename: the default filename that should be used. It can be "*.*".
- Result: full path to the final unpacked file.
The file is not removed! Useful if you want to let your end users "download" files from your publication. | | GetTemporaryFilename | Returns the full path to a temporary file. function GetTemporaryFilename: String; | This function may be useful for functions like SaveFormResultsToFile. | | RunAProgram | Executes the specified executable program file. function RunAProgram(const Filename, Params, WorkingDir: String; Wait: Boolean; DispWindow: Integer): Boolean; | - Filename: full path to the .exe file you want to run.
- Params: optional command line parameters.
- WorkingDir: the path to the folder that should be set as the system current one.
- Wait: indicates whether the publication "sleeps" until the end of the program's execution.
- DispWindow: window state. May be SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED, SW_HIDE...
- Result: True if the program was run successfully.
It does not work with document files. |
Miscellaneous options
| Function name | Description & prototype | Parameters, example, remarks |
|---|
| ReplaceString | Returns a string with occurrences of one substring replaced by another substring function ReplaceString(const Original,OldPattern, NewPattern: string): String; | - Original: original string with old patterns.
- OldPattern: string to replace.
- NewPattern: the new string that takes the place.
- Result: the new string will all replaced patterns.
Similar to StringReplace in Delphi SysUtils. | | RegisterPub | Registers a Trial publication. Only working if you have Trial publication. You should then call ActivateCertificate in order to apply changes. procedure RegisterPub(name, data1, data2, key: String); | - Name: user name.
- Data1, Data2: optional. Used to generate the key.
- Key: the key specified by user.
This function will replace the current registration information items with the provided ones. For security reasons, it does not check the validity of the key: at the next startup, the publication will run with the certificate whose key was made for. | | ActivateCertificate | Forces the trial publication to activate the certificate that matches the current registration items saved by RegisterPub. function ActivateCertificate: String; | Should only be used after a call to RegisterPub, and followed by ExitPublication. Returns the name of the selected certificate. Blank if no certificate matches. | | GetCurrentCertificate | Returns the name of the current certificate. Only working if you have Trial publication. function GetCurrentCertificate: String; | | | SetDefaultCertificate | Sets the current certificate to default one. procedure SetDefaultCertificate; | This function causes the publication to come back to the Default certificate. If the default certificate has an expiration period, this period is automatically expired. | | MD5OfAString | Gets the MD5 sum of the specified string. function MD5OfAString(const Str: String): String; | - Str: string you want to get the MD5 sum of.
- Result: string format of the MD5 sum.
| | InputBox | Prompts your end users for a query (a dialog box is shown) function InputBox(const Query, Title, Default: String): String; | - Query: the prompt text. Tells your end users what you are asking.
- Title: title of the dialog box.
- Default: the default value to display in the field.
- Result: returns what end users answered or a blank value if they chose "Cancel".
| | ParamStr | Returns the index-th parameter passed to the program using the command line. function ParamStr(index: Integer): String; | - Index: index of the parameter you want to obtain.
Note: use double quotes to wrap multiple words as one parameter (such as long file names containing spaces). | | StartTimer | Starts a timer to trigger an event, either one time or repeatedly, after a measured interval. Write the code that you want to occur at the specified time inside the UserMain's OnTimer function event. procedure StartTimer(const TimerName: String; const Interval: Cardinal); | - TimerName: name of the custom timer. NOT CURRENTLY USED. Just leave blank.
- Interval: determines the amount of time, in milliseconds, that passes before the timer initiates another OnTimer event.
For example 1000 for one second. Note: A 0 value is valid, however the timer won't call an OnTimer event for a value of 0.
| | StopTimer | Stops a timer that was created by StartTimer. procedure StopTimer(const TimerName: String); | - TimerName: name of the custom timer. NOT CURRENTLY USED. Just leave blank.
| | StrAnsiToUtf8 | Converts a normal ansi string to a UTF8 encoded string. function StrAnsiToUtf8(const Str: String): String; | - Str: the string you want to convert.
| | StrUtf8ToAnsi | Converts a UTF8 encoded string to a normal ansi string. function StrUtf8ToAnsi(const Str: String): String; | - Str: the string you want to convert.
| | StrEncodeBinHex | Encodes binary data in Str as BINHEX. The function returns the BINHEX encoded data as string, without any linebreaks. function StrEncodeBinHex(const Str: String): String; | - Str: the string you want to convert.
| | StrDecodeBinHex | Decodes BINHEX data in Str into binary data. The function returns the binary data as string. The Str string may contain linebreaks and control characters, these will be stripped.function StrDecodeBinHex(const Str: String): String; | - Str: the string you want to convert.
| | IsIEEngine | Indicates the type of publication: HTML Viewer or IE Browser. function IsIEEngine: Boolean; | Returns True if the publication is an IE Browser one. This function is used internally. |
The following internal functions are also supported, but they are not described here. For a further description, please go to: http://www.delphibasics.co.uk/ByUnit.asp?Unit=SysUtils procedure Beep; function Trim(const S: string): string; function TrimLeft(const S: string): string; function TrimRight(const S: string): string; function GetCurrentDir: string; function SetCurrentDir(const Dir: string): Boolean; function ExpandFileName(const FileName: string): string; function ExpandUNCFileName(const FileName: string): string; function ExtractRelativePath(const BaseName, DestName: string): string; function ExtractFileDir(const FileName: string): string; function ExtractFileDrive(const FileName: string): string; function ExtractFileExt(const FileName: string): string; function ExtractFileName(const FileName: string): string; function ExtractFilePath(const FileName: string): string; function ChangeFileExt(const FileName, Extension: string): string; function FileSearch(const Name, DirList: string): string; function RenameFile(const OldName, NewName: string): Boolean; function DeleteFile(const FileName: string): Boolean; function CreateDir(const Dir: string): Boolean; function RemoveDir(const Dir: string): Boolean; function CompareStr(const S1, S2: string): Integer; function MCompareText(const Str1, Str2: String): Integer; // Same as AnsiCompareText function CompareText(const S1, S2: string): Integer; function IncludeTrailingBackslash(const S: string): string; function Format1(const Format, S1: String): String; (similar to Format) function Format2(const Format, S1, S2: String): String; (similar to Format) function Format3(const Format, S1, S2, S3: String): String; (similar to Format) function Format4(const Format, S1, S2, S3, S4: String): String; (similar to Format) function SysErrorMessage(ErrorCode: Integer): String; function Ord(C: Char): Byte; function Copy(S: String; Indx, Count: Integer): String; function Length(s: String): Longint; function Lowercase(s: string): String; function StrGet(S: String; I: Integer): Char; function StringOfChar(c: Char; I : Longint): String; function StrSet(c: Char; I: Integer; var s: String): Char; function Uppercase(s: string): String; procedure Delete(var S: String; Indx, Count: Integer); procedure Insert(Source: String; var Dest: String; Indx: Integer); function Pos(SubStr, S: String): Integer; function StrToIntDef(s: string; def: Longint): Longint; function StrToInt(s: string): Longint; function IntToStr(i: Longint): String; function Now: TDateTime; function Date: TDateTime; function Time: TDateTime; function DateToStr(Date: TDateTime): string; function FormatDateTime(const Format: string; DateTime: TDateTime): string; function StrToDate(const S: string): TDateTime; function DayOfWeek(Date: TDateTime): Integer; Some Delphi classes like TStringList are also supported. Introduction to Scripting
Using the Script Manager
|