Dynamic Lotusscript
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的更多相关文章
- var和dynamic的区别
1.var 1.均是声明动态类型的变量. 2.在编译阶段已经确定类型,在初始化的时候必须提供初始化的值. 3.无法作为方法参数类型,也无法作为返回值类型. 2.dynamic 1.均是声明动态类型的变 ...
- 遍历dynamic的方式
一.遍历ExpandoObject /// <summary> /// 遍历ExpandoObject /// </summary> [TestMethod] public v ...
- C# dynamic 动态创建 json
1. 如何通过C# 的dynamic 创建如下json 对象? { "query": { "match": [{ "name": " ...
- BZOJ 1901: Zju2112 Dynamic Rankings[带修改的主席树]【学习笔记】
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 7143 Solved: 2968[Su ...
- 当类型为dynamic的视图模型遭遇匿名对象
当年在ASP.NET MVC 1.0时代我提到,在开发时最好将视图的Model定制为强类型的,这样可以充分利用静态检查功能进行排错.不过有人指出,这么做虽然易于静态检查,但是定义强类型的Model类型 ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- 理解C# 4 dynamic(4) – 让人惊艳的Clay
Clay非常类似于ExpandoObject, 可以看做是ExpandoObject的加强版. 它们能够让我们在不需要定义类的情况下,就构建出我们想要的对象.Clay和ExpandoObject相比, ...
- [原创] C# dynamic拼接Json串
using Newtonsoft.Json; 之前拼接两个json串,是用的这样的代码 , json1.Length - ); json2 = json2.Insert(json2 - , tmp); ...
- dynamic 用法
private static string GetNameValue(object value) { dynamic obj = value; try { return obj.Name; } cat ...
随机推荐
- CountDownLatch使用场景及分析
JDk1.5提供了一个非常有用的包,Concurrent包,这个包主要用来操作一些并发操作,提供一些并发类,可以方便在项目当中傻瓜式应用. JDK1.5以前,使用并发操作,都是通过Thread,Run ...
- 【deep learning学习笔记】注释yusugomori的DA代码 --- dA.h
DA就是“Denoising Autoencoders”的缩写.继续给yusugomori做注释,边注释边学习.看了一些DA的材料,基本上都在前面“转载”了.学习中间总有个疑问:DA和RBM到底啥区别 ...
- Java语言:JAVA8 十大新特性详解(zz)
关键词: Lambda表达式.函数式接口.方法与构造函数引用.接口的默认方法 原文地址: http://www.jb51.net/article/48304.htm 本教程将Java8的新特新逐一列出 ...
- 创建SQL作业错误的解决方法(不能将值 NULL 插入列 'owner_sid',表 'msdb.dbo.sysjobs';列不允许有空值。)
在用SQL语句创建SQL Server作业时有时出现如下错误: 消息 515,级别 16,状态 2,过程 sp_add_job,第 137 行 不能将值 NULL 插入列 'owner_sid',表 ...
- CentOS下ssh sftp配置及权限设置
运营有异地传输文件的需求,但如果通过QQ等即时通讯软件,不利于文件的集中管理,不方便.而我们办公室的内网机器无法提供外网访问方法,且传输的内容不合适放到公共的网盘或者是云存储上,所以只能用线上负载较低 ...
- tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别
tf.contrib.rnn.static_rnn与tf.nn.dynamic_rnn区别 https://blog.csdn.net/u014365862/article/details/78238 ...
- 最新自然语言处理(NLP)四步流程:Embed->Encode->Attend->Predict
http://blog.csdn.net/jdbc/article/details/53292414 过去半年以来,自然语言处理领域进化出了一件神器.此神器乃是深度神经网络的一种新模式,该模式分为:e ...
- ML、DL相关资源
1. http://x-algo.cn/index.php/category/nlp/
- 创业公司做数据分析(四)ELK日志系统 (转)
http://blog.csdn.net/zwgdft/article/details/53842574 作为系列文章的第四篇,本文将重点探讨数据采集层中的ELK日志系统.日志,指的是后台服务中产生的 ...
- 解决excel日期变成数字的问题
在Excel中如果单元格的公式是日期格式,那么引用后的数值是错误的[不是日期格式而被转换成数字类型了],这种情况显然不是我们想要的结果 解决办法: 在公式中强制转成文本类型即可(="Date ...