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 ...
随机推荐
- FreeMarker:Java模板引擎
本资源由 伯乐在线 - 黄余粮 整理 FreeMarker 是一个模板引擎,一个基于模板生成文本输出的通用工具,使用纯Java编写.FreeMarker被设计用来生成HTML Web页面,特别是基于M ...
- Android ActionBar使用介绍
一.什么是ActionBar 有图有真相,看一下图片就了解的差不多了 对于大多数应用,操作栏可以分割为 4 个不同的功能区域. 1. 应用图标 应用图标是您应用的标志.在应用图标位置摆放您自己的 lo ...
- C/C++ 分支预测(likely unlikely)
看一些代码时,会遇到likely unlikely, 查了查网上的资料,结合自己的理解记录一下. 1. 一些概念 指令周期是指执行一条指令所需要的时间,一般由若干个机器周期组成,是从取指令.分析指令到 ...
- SharePoint 列表权限控制
一提到sharepoint 我相信权限控制一定会是一个很重要的话题,尤其是对列表的权限控制,创建.修改.查看权限.其实网上这方面的资料已经很多了,尤其是以下2篇文章,后来索性把CodeArt_Perm ...
- WebService入门Demo
以前写博客最主要的就是不知道写什么东西,现在感觉能写点东西,就是感觉博客随笔的标题挺难取的,最近工作中刚好用到了WebService,刚好可以写一篇博客.去年工作的时候自己也用到过,只是知道调用一些W ...
- 8天学通MongoDB——第一天 基础入门(转)
关于mongodb的好处,优点之类的这里就不说了,唯一要讲的一点就是mongodb中有三元素:数据库,集合,文档,其中“集合” 就是对应关系数据库中的“表”,“文档”对应“行”. 一: 下载 上Mon ...
- Laravel学习笔记之Session源码解析(上)
说明:本文主要通过学习Laravel的session源码学习Laravel是如何设计session的,将自己的学习心得分享出来,希望对别人有所帮助.Laravel在web middleware中定义了 ...
- Siamese Network简介
Siamese Network简介 Siamese Network 是一种神经网络的框架,而不是具体的某种网络,就像seq2seq一样,具体实现上可以使用RNN也可以使用CNN. 简单的说,Siame ...
- Java提高篇(转)
http://www.cnblogs.com/mfrank/category/1118474.html Day1 抽象类 Day2 接口 Day3 抽象类与接口的比较 Day4 Java中的回调 Da ...
- Kafka:ZK+Kafka+Spark Streaming集群环境搭建(七)针对hadoop2.9.0启动DataManager失败问题
DataManager启动失败 启动过程中发现一个问题:slave1,slave2,slave3都是只启动了DataNode,而DataManager并没有启动: [spark@slave1 hado ...