Introduction

This short article gives an introduction to the underrated Execute method that is available in Lotusscript. The basics are explained through some simple examples, after which two suggestions are made for advanced usage.

The basics

The Execute method in Lotusscript is an underused feature that can be extremely powerful when used properly. This method allows you to dynamically load, execute, and unload Lotusscript modules. The syntax is extremely simple:

Execute ( text )

Where text is a string containing the script to execute. Here's a simple example:

Sub Initialize    Dim strCode As String    strCode = | msgbox "I'm dynamic!" |    Execute( strCode ) End Sub

When you run this code, it will display a message box that says "I'm dynamic!".  Now let's have a look at a dynamic script that spans multiple lines:

Sub Initialize    Dim strCode As String    strCode = |    Dim strMessage as String    strMessage = "I'm dynamic"    msgbox strMessage     |    Execute( strCode ) End Sub

Note that pipeline characters are used to span multiple lines of Lotusscript into the strCode variable.  This second example has exactly the same effect as the first, yet this time the dynamic code spans multiple lines and the message to prompt is defined in a variable.

The essence of the Execute method should be clear by now; one can dynamically run Lotusscript at runtime. The next two paragraphs demonstrate two interesting applications of this feature.

Dynamic class loading

Besides the simple series of statements from the previous examples, one can also include the Use and Declare keywords in the dynamic script. Consider the following script:

Sub Initialize    Dim strCode as String    strCode = |    Use "libArrayManager"    Dim AM as ArrayManager    Set AM = new ArrayManager()    |    Execute strCode End Sub

This dynamic code loads a custom fictional class ArrayManager and instantiates a new ArrayManager object from it. The point in this example is that in line 4 we are dynamically loading a module.  Thus, at runtime, we can programatically decide to load or not load a module. This technique is called Dynamic Class Loading. When applied correctly this technique can lead to performance gains, because only modules that are needed are actually loaded.

This is not a new technique, I have been using it successfully for years. The first time it appeared was in the must-read redbook Performance Considerations for Domino Applications. Bill Buchan has presented it at Lotussphere '05 as well, so I'll refer you to those two sources for the full details.

Web services

The second advanced application of the Execute method comes quite close to Web Services. One of the key concepts of a web service is that you can dynamically call functions (services) and retrieve the return values, if any. The other concept is that you can do this from anywhere, independant of your calling client, OS or hardware.

Allow me to demonstrate how you can realize the first concept through a simple example:

Declarations    Dim strReturnVal as String Sub Initialize    Dim strCode as String    Dim strModule as String    Dim strFunction as String    Dim strParam as String
   strModule = "libUser"    strFunction = "getCountry"    strParam = "Orky Dorky"
   strCode = |    Use | & strModule & |    strReturnVal = | & strFunction & |(| & strParam & |)|    Execute strCode    Msgbox strReturnVal End Sub

Look at that. Everything is dynamic, the module to load, the function to execute, and the parameter to pass on. Pay particular attention to the bold line in the example. Key concept here is that we can communicate between our static and dynamic script through variables.  Note that this only works for globally declared variables, that's why strReturnVal is declared in the top line of the example.

So how does this come close to a web service? We have proven that we can call a function and pass parameters based on data.  In the example, this data is defined in variables,  but they might have been coming from a SOAP message, email, or Notes document.

Of course, the example is too simple. Not all functions have a return value. Not all functions have exactly one parameter of that data type. Just think of the base concept, the road for web services is paved. Available from Notes 4.6, go figure!

» Excellent .Really usefull «

Dynamic Lotusscript的更多相关文章

  1. var和dynamic的区别

    1.var 1.均是声明动态类型的变量. 2.在编译阶段已经确定类型,在初始化的时候必须提供初始化的值. 3.无法作为方法参数类型,也无法作为返回值类型. 2.dynamic 1.均是声明动态类型的变 ...

  2. 遍历dynamic的方式

    一.遍历ExpandoObject /// <summary> /// 遍历ExpandoObject /// </summary> [TestMethod] public v ...

  3. C# dynamic 动态创建 json

    1. 如何通过C# 的dynamic 创建如下json 对象? { "query": { "match": [{ "name": " ...

  4. BZOJ 1901: Zju2112 Dynamic Rankings[带修改的主席树]【学习笔记】

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7143  Solved: 2968[Su ...

  5. 当类型为dynamic的视图模型遭遇匿名对象

    当年在ASP.NET MVC 1.0时代我提到,在开发时最好将视图的Model定制为强类型的,这样可以充分利用静态检查功能进行排错.不过有人指出,这么做虽然易于静态检查,但是定义强类型的Model类型 ...

  6. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  7. 理解C# 4 dynamic(4) – 让人惊艳的Clay

    Clay非常类似于ExpandoObject, 可以看做是ExpandoObject的加强版. 它们能够让我们在不需要定义类的情况下,就构建出我们想要的对象.Clay和ExpandoObject相比, ...

  8. [原创] C# dynamic拼接Json串

    using Newtonsoft.Json; 之前拼接两个json串,是用的这样的代码 , json1.Length - ); json2 = json2.Insert(json2 - , tmp); ...

  9. dynamic 用法

    private static string GetNameValue(object value) { dynamic obj = value; try { return obj.Name; } cat ...

随机推荐

  1. OpenCV教程(47) sift特征和surf特征

         在前面三篇教程中的几种角检测方法,比如harris角检测,都是旋转无关的,即使我们转动图像,依然能检测出角的位置,但是图像缩放后,harris角检测可能会失效,比如下面的图像,图像放大之前可 ...

  2. javascript对象constructor属性

    概述 返回一个指向创建了该对象原型的函数引用.需要注意的是,该属性的值是那个函数本身,而不是一个包含函数名称的字符串.对于原始值(如1,true 或 "test"),该属性为只读. ...

  3. ofstream的使用方法--超级精细。C++文件写入、读出函数(转)

    ofstream的使用方法ofstream是从内存到硬盘,ifstream是从硬盘到内存,其实所谓的流缓冲就是内存空间;  在C++中,有一个stream这个类,所有的I/O都以这个“流”类为基础的, ...

  4. 手把手实现腾讯qq拖拽删去效果(二)

    这节,就一个任务如何把上节自定义的翻页动画控件整进下拉列表中去. 由于是自定义的下拉列表控件,我们需要自定义能够上啦下滑的listview,这势必会造成这个问题,上拉刷新要响应相应touch事件,拖拽 ...

  5. [转]Python机器学习工具箱

    原文在这里  Python在科学计算领域,有两个重要的扩展模块:Numpy和Scipy.其中Numpy是一个用python实现的科学计算包.包括: 一个强大的N维数组对象Array: 比较成熟的(广播 ...

  6. Java-JUC(一):volatile引入

    问题背景: volatile是为了解决内存可见性而生的,什么是内存不可见性呢? 以下边的代码为例: package com.dx.juc; public class VoltileTest { pub ...

  7. rpcserver不可用

    今天用打印机.电脑一直弹出rpcserver不可用.如图: 解决的方法:将例如以下服务启动就可以解决,如图:

  8. 阿里云centos安装ftp与svn过程

    1.下载xshell或者secureCRT 2.登录centos或者服务器 3.安装vsftpd [root@xxx]# yum install vsftpd //安装vsftpd [root@xxx ...

  9. 关于Puppet不得不说的故事

    Puppet对于做DevOps的同学来说,是个熟悉的名字,但仍有许多人并不了解它.那么我先来简单介绍一下:Puppet是由Puppetlabs公司开发的系统管理框架和工具集,被用于IT服务的自动化管理 ...

  10. 微服务架构实践 - 你只懂docker与spring boot就够了吗?

    微服务架构实践 - 你只懂docker与spring boot就够了吗? 作者 浮云发发 已关注 2017.02.27 02:50* 字数 2613 阅读 2583评论 6喜欢 35赞赏 2 微服务并 ...