TQAxScriptManager Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQAxScriptManager Class Reference
[TQAxContainer module]

The TQAxScriptManager class provides a bridge between application objects and script code. More...

This class is part of the TQt ActiveTQt Extension.

`#include <qaxscript.h>`

Inherits TQObject.

List of all member functions.

## Public Members

- TQAxScriptManager ( TQObject * parent = 0, const char * name = 0 )
- ~TQAxScriptManager ()
- void addObject ( TQAxBase * object )
- void addObject ( TQObject * object )
- TQStringList functions ( TQAxScript::FunctionFlags flags = TQAxScript::FunctionNames ) const
- TQStringList scriptNames () const
- TQAxScript * script ( const TQString & name ) const
- TQAxScript * load ( const TQString & code, const TQString & name, const TQString & language )
- TQAxScript * load ( const TQString & file, const TQString & name )
- TQVariant call ( const TQString & function, const TQVariant & var1 = TQVariant ( ), const TQVariant & var2 = TQVariant ( ), const TQVariant & var3 = TQVariant ( ), const TQVariant & var4 = TQVariant ( ), const TQVariant & var5 = TQVariant ( ), const TQVariant & var6 = TQVariant ( ), const TQVariant & var7 = TQVariant ( ), const TQVariant & var8 = TQVariant ( ) )
- TQVariant call ( const TQString & function, TQValueList<TQVariant> & arguments )

## Signals

- void error ( TQAxScript * script, int code, const TQString & description, int sourcePosition, const TQString & sourceText )

## Static Public Members

- bool registerEngine ( const TQString & name, const TQString & extension, const TQString & code = TQString ( ) )
- TQString scriptFileFilter ()

## Detailed Description

This class is defined in the TQt ActiveTQt Extension, which can be found in the `qt/extensions` directory. It is not included in the main TQt API.

The TQAxScriptManager class provides a bridge between application objects and script code.

The TQAxScriptManager acts as a bridge between the COM objects embedded in the TQt application through TQAxObject or TQAxWidget, and the scripting languages available through the Windows Script technologies, usually JScript and VBScript.

Create one TQAxScriptManager for each separate document in your application, and add the COM objects the scripts need to access using addObject(). Then load() the script sources and invoke the functions using call().

Warning: This class is not available with the bcc5.5 and MingW compilers.

## Member Function Documentation

### TQAxScriptManager::TQAxScriptManager ( TQObject * parent = 0, const char * name = 0 )

Creates a TQAxScriptManager object. parent and name are passed on to the TQObject constructor.

It is usual to create one TQAxScriptManager for each document in an application.

### TQAxScriptManager::~TQAxScriptManager ()

Destroys the objects, releasing all allocated resources.

### void TQAxScriptManager::addObject ( TQAxBase * object )

Adds object to the manager. Scripts handled by this manager can access the object in the code using the object's name property.

You must add all the necessary objects before loading any scripts.

### void TQAxScriptManager::addObject ( TQObject * object )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Adds a generic COM wrapper for object to the manager. object must be exposed as a COM object using the functionality provided by the TQAxServer module.. Applications using this function you must link against the qaxserver library.

### TQVariant TQAxScriptManager::call ( const TQString & function, const TQVariant & var1 = TQVariant ( ), const TQVariant & var2 = TQVariant ( ), const TQVariant & var3 = TQVariant ( ), const TQVariant & var4 = TQVariant ( ), const TQVariant & var5 = TQVariant ( ), const TQVariant & var6 = TQVariant ( ), const TQVariant & var7 = TQVariant ( ), const TQVariant & var8 = TQVariant ( ) )

Calls function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8 as arguments and returns the value returned by the function, or an invalid TQVariant if the function does not return a value or when the function call failed. The call returns when the script's execution has finished.

In most script engines the only supported parameter type is "const TQVariant&", for example, to call a JavaScript function

        function setNumber(number)
        {
            n = number;
        }

use

        TQValueList args;
        args << 5;
        script->call("setNumber(const TQVariant&)", args);

As with dynamicCall the parameters can directly be embedded in the function string.

        script->call("setNumber(5)");

However, this is slower.

Functions provided by script engines that don't support introspection are not available and must be called directly using TQAxScript::call() on the respective script object.

Note that calling this function can be significantely slower than using call() on the respective TQAxScript directly.

### TQVariant TQAxScriptManager::call ( const TQString & function, TQValueList<TQVariant> & arguments )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Calls function passing arguments as parameters, and returns the result. Returns when the script's execution has finished.

### void TQAxScriptManager::error ( TQAxScript * script, int code, const TQString & description, int sourcePosition, const TQString & sourceText )`[signal]`

This signal is emitted when an execution error occured while running script.

code, description, sourcePosition and sourceText contain information about the execution error.

### TQStringList TQAxScriptManager::functions ( TQAxScript::FunctionFlags flags = TQAxScript::FunctionNames ) const

Returns a list with all the functions that are available. Functions provided by script engines that don't support introspection are not included in the list. The functions are either provided with full prototypes or only as names, depending on the value of flags.

### TQAxScript * TQAxScriptManager::load ( const TQString & code, const TQString & name, const TQString & language )

Loads the script source code using the script engine for language. The script can later be referred to using its name which should not be empty.

The function returns a pointer to the script for the given code if the code was loaded successfully; otherwise it returns 0.

If language is empty it will be determined heuristically. If code contains the string "End Sub" it will be interpreted as VBScript, otherwise as JScript. Additional script engines can be registered using registerEngine().

You must add all the objects necessary (using addObject()) before loading any scripts. If code declares a function that is already available (no matter in which language) the first function is overloaded and can no longer be called via call(); but it will still be available by calling its script directly.

See also addObject(), scriptNames(), and functions().

### TQAxScript * TQAxScriptManager::load ( const TQString & file, const TQString & name )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Loads the source code from the file. The script can later be referred to using its name which should not be empty.

The function returns a pointer to the script engine for the code in file if file was loaded successfully; otherwise it returns 0.

The script engine used is determined from the file's extension. By default ".js" files are interpreted as JScript files, and ".vbs" and ".dsm" files are interpreted as VBScript. Additional script engines can be registered using registerEngine().

### bool TQAxScriptManager::registerEngine ( const TQString & name, const TQString & extension, const TQString & code = TQString ( ) )`[static]`

Registers the script engine called name and returns true if the engine was found; otherwise does nothing and returns false.

The script engine will be used when loading files with the given extension, or when loading source code that contains the string code.

### TQAxScript * TQAxScriptManager::script ( const TQString & name ) const

Returns the script called name.

You can use the returned pointer to call functions directly through TQAxScript::call(), to access the script engine directly, or to delete and thus unload the script.

### TQString TQAxScriptManager::scriptFileFilter ()`[static]`

Returns a file filter listing all the supported script languages. This filter string is convenient for use with TQFileDialog.

### TQStringList TQAxScriptManager::scriptNames () const

Returns a list with the names of all the scripts.

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.