Built-in Commands

www.altova.com Imprimer cette rubrique Page précédente Un niveau supérieur Page suivante

Accueil >  Programmers' Reference > Scripting Editor > Programming Points >

Built-in Commands

This section lists:

 

Built-in commands
alert
conform
doevents
CreateForm
lastform
prompt
ShowForm
watchdog

 

.NET interoperability commands
CLR.Create
CLR.Import
CLR.LoadAssembly
CLR.ShowImports
CLR.ShowLoadedAssemblies
CLR.Static

 

 

Built-in commands

The following built-in commands are available.

 

 

ShowForm(strFormName : String)

Instantiates a New Form object from the given form name and immediately shows it as Dialog.

Return Value: A Number that represents the generated DialogResult (System.Windows.Forms.DialogResult).

 

Example:

var dialogResult = ShowForm( "FormName" );

 

Shows Form "FormName" as Dialog:

 

ShowForm

 

The DialogResult can be evaluated e.g. by:

 

if ( dialogResult == CLR.Static( "System.Windows.Forms.DialogResult" ).OK )
       alert( "ok" );
else
       alert( "cancel" );

 

 

CreateForm(strFormName : String)

Instantiates a New Form object from the given Form name.

Return Value: The Form object (System.Windows.Forms.Form) of the given name, or null if no Form with such name exists.

 

Example:

var myForm = CreateForm( "FormName" );
if ( myForm != null )
{
       myForm.textboxFirstName.Text = "Daniel";
       myForm.textboxLastName.Text = "Smith";
       var dialogResult = myForm.ShowDialog();
}        

 

Shows Form "FormName" as Dialog - TextBoxes are initialized:

 

CreateForm

 

The DialogResult can be evaluated e.g. by:

 

if ( dialogResult == CLR.Static( "System.Windows.Forms.DialogResult" ).OK )
       alert( "ok" );
else
       alert( "cancel" );

 

 

lastform

This global field can be used to conveniently access the last form object that was created.

Return Value: Returns a reference to the last form object  (System.Windows.Forms.Form)  that was successfully instantiated via CreateForm() or ShowForm().

 

Example:

CreateForm( "FormName" );
if ( lastform != null )
{
       lastform.textboxFirstName.Text = "Daniel";
       lastform.textboxLastName.Text = "Smith";
       var dialogResult = lastform.ShowDialog();
}

 

Shows Form "FormName" as Dialog - TextBoxes are initialized (similar to the CreateForm example above):

 

CreateForm

 

 

doevents()

Processes all Windows messages currently in the message queue.

Return Value: None

 

Example:

for ( i=0; i < nLongLastingProcess; ++)
{
       // do long lasting process
       doevents(); // process windows messages; give UI a chance to update
}

 

 

watchdog(bEnable : boolean)

Long running CPU-intensive scripts cause the watchdog to ask the user if the script should be terminated. The watchdog() method is used to disable or enable this behavior.

Per default the watchdog is enabled.

Return Value: None

 

Example:

watchdog( false );        // disable watchdog - we know the next statement is CPU intensive but it will terminate for sure
doCPUIntensiveScript();
watchdog( true );        // re-enable watchdog                

 

Usage tip:

Calling watchdog(true) can also be used to reset the watchdog. This can be useful before executing long running (CPU intensive) tasks to ensure they have the maximum allowed script processing quota.

 

 

alert(strMessage : String) or MsgBox(strMessage : String)

An alert box is used to show a given message. The user will have to click "OK" to proceed.

Return Value: None

 

Example:

alert( "Hello World" );

 

alert

 

 

confirm(strMessage : String)

Opens a dialog that shows the given confirm message.

A confirm box is often used to verify or accept something. The user will have to click either "OK" or "Cancel" to proceed.

Return Value: A Boolean that represents the users answer. If the user clicks "OK", the dialog returns true, if the user clicks "Cancel", the dialog returns false.

 

Example:

if ( confirm( "Continue processing?" ) == false )
       return;

 

confirm

 

 

prompt(strMessage : String, strDefault : String)

Opens a dialog that shows the given prompt message and a TextBox control with a default answer.

A prompt box is often used to input a simple string value.

Return Value: A String that contains the TextBox value or null if the user selected "Cancel".

 

Example:

var name = prompt( "Please enter your name", "Daniel Smith" );
if ( name != null )
       alert( "Hello " + name + "!" );        

 

prompt

 

 

 

.NET interoperability commands

To allow further interoperability with the .NET Framework additional functions are provided under CLR.

 

 

CLR.Import(strNamespaceCLR : String)

This is the scripting equivalent to the C# using / VB.Net imports keyword. This allows to leave out the given namespaces in successive calls like CLR.Create() and CLR.Static().

Return Value: None

 

Example:

Instead of always having to use full qualified names:

 

if ( ShowForm( "FormName" ) == CLR.Static( "System.Windows.Forms.DialogResult" ).OK )
{
       var sName = lastform.textboxFirstName.Text + " " + lastform.textboxLastName.Text;
       CLR.Static( "System.Windows.Forms.MessageBox" ).Show( "Hello " + sName );
}

 

one can import namespaces and use the short form:

 

CLR.Import( "System.Windows.Forms" );
if ( ShowForm( "FormName" ) == CLR.Static( "DialogResult" ).OK )
{
       var sName = lastform.textboxFirstName.Text + " " + lastform.textboxLastName.Text;
       CLR.Static( "MessageBox" ).Show( "Hello " + sName );
}

 

Please note:

Importing a namespace does not add or load the corresponding assembly to the scripting project!

Assemblies can be added to the scripting project dynamically (at runtime) in the source code by using CLR.LoadAssembly.

 

 

CLR.ShowImports()

Opens a MessageBox dialog that shows the currently imported namespaces. The user will have to click "OK" to proceed.

Return Value: None

 

Example:

CLR.ShowImports();

 

ShowImports

 

 

CLR.LoadAssembly(strAssemblyNameCLR : String)

Loads the .NET assembly with the given long assembly name or file path.

Return Value: A Boolean value. True if the assembly could be loaded, false otherwise.

 

Example:

// set clipboard text (if possible)
// System.Windows.Clipboard is part of the PresentationCore assembly, so load this assembly first:
if ( CLR.LoadAssembly( "PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", true ) )
{
       var clipboard = CLR.Static( "System.Windows.Clipboard" );
       if ( clipboard != null )
               clipboard.SetText( "HelloClipboard" );
}

 

 

CLR.ShowLoadedAssemblies()

Opens a MessageBox dialog that shows the currently loaded assemblies. The user will have to click "OK" to proceed.

Return Value: None

 

Example:

CLR.ShowLoadedAssemblies();

 

ShowLoadedAssemblies

 

 

CLR.Create(strTypeNameCLR : String, constructor arguments ...)

Creates a new .NET object instance for the given typename. If more than one argument is passed the successive arguments are interpreted as the arguments for the constructor of the .NET object.

Return Value: A reference to the created .NET object

 

Examples:

var objArray = CLR.Create("System.Collections.ArrayList");

 

var newItem = CLR.Create( "System.Windows.Forms.ListViewItem", "NewItemText" );

 

var coll = CLR.Create( "System.Collections.Generic.List<System.String>" );

 

CLR.Import( "System" );
CLR.Import( "System.Collections.Generic" );
var dictionary = CLR.Create( "Dictionary< String, Dictionary< String, String > >" );

 

 

CLR.Static(strTypeNameCLR : String)

Gives access to .NET types that have no instances and contain only static members.

Return Value: A reference to the static .NET object

 

Examples:

var enumValStretch = CLR.Static( "System.Windows.Forms.ImageLayout" ).Stretch

 

var clipboard = CLR.Static( "System.Windows.Clipboard" );
clipboard.SetText( "HelloClipboard" );

 

if ( ShowForm( "FormName" ) == CLR.Static( "System.Windows.Forms.DialogResult" ).OK )
       alert( "ok" );
else
       alert( "cancel" );

© 2019 Altova GmbH