博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Auto-generate LotusScript setter and getter properties for class variables
阅读量:7034 次
发布时间:2019-06-28

本文共 4372 字,大约阅读时间需要 14 分钟。

Here's the problem. You're using object-oriented LotusScript to create classes and objects. Like a good object-oriented LotusScript developer, you're declaring all your class variables as "Private" and then writing "
Setter" and "
Getter" properties to allow access to them.

The truth is, most of the "Setter" and "Getter" properties that you would write offer direct read/write access to those variables anyway -- and writing them out is such a pain! You could cheat and declare the class variables as public or you could have a Lotus Notes form generate them for you.

Here is the code for a button that will do just this:

private m_MyVar1 as stringprivate m_MyVar2 as Variantprivate m_MyVar3 as Integerprivate m_MyVar4() as string

That will generate these:

Public Property Get MyVar1 as StringMyVar1 = me.m_MyVar1End PropertyPublic Property Set MyVar1 as Stringme.m_MyVar1 = MyVar1End PropertyPublic Property Get MyVar2 as VariantMyVar2 = me.m_MyVar2End PropertyPublic Property Set MyVar2 as Variantme.m_MyVar2 = MyVar2End Property... and so on.

To further set this up, create a Lotus Notes form in any Lotus Notes database and put two text fields in it.

These text fields should be labeled as:

  • Input: This is a multi-value Lotus Notes text field. Set the multi-value options tick boxes to use "NewLine" for both display and input.

Output: This is a single value Lotus Notes text field.

Now follow these steps:

  1. Create a button on the form and paste the button code below into its LotusScript Click event.

Create a new Lotus Notes document from the form and paste your class variable declarations into the
Input field.

Click the button.

The "Setter" and "Getter" properties will be created in the Output field. You can then copy and paste the LotusScript below into your class definition code:  

Button codeDim session As New NotesSessionDim ws As New NotesUIWorkspaceDim uidoc As NotesUIDocumentDim doc As NotesDocumentDim inputVar As VariantSet uidoc = ws.CurrentDocumentSet doc = uidoc.documentCall doc.ComputeWithForm(False, False)inputVar = doc.InputIf inputVar(0) = "" ThenMessagebox "No input found"Exit SubEnd If%REMAssumptions are that class variables will declared thus private m_MyVar1 as string private m_MyVar2 as Variant private m_MyVar3 as Integer private m_MyVar4() as stringand so on. We use the Split function to create a variant array (tempVar) of 4 members. These will betempVar(0) = the word "Private".tempVar(1) = the variable's nametempVar(2) = the word "as"tempvar(3) = the variable's type.You need two text fields on a form:"Input" = multi-value Text field. Set the multi-value options tickboxes to use NewLine."Output" = single value Text field%END REMDim outputString As StringDim tempString As StringDim tempVar As VariantDim variableName As StringDim setgetVariableName As StringDim variableType As StringDim NL As StringoutputString$ = ""Dim classVariablePrefix As StringclassVariablePrefix$ = "m_"NL$ = Chr$(13) & Chr$(10) ' True for Windoze only. Should change for Mac or Linux clients.Forall inputLine In inputVartempVar = Split(inputLine, " ")variableName = Trim(tempVar(1))variableType = Trim(tempVar(3))If Instr(variableName, "(") > 0 Then ' must be an array, so need to declare the set and get as Variant variableName$ = Strleft(variableName$, "(") variableType$ = "Variant"End IfIf Instr(variableName$, classVariablePrefix$) > 0 Then setgetVariableName$ = Strrightback(variableName$, classVariablePrefix$) Else setgetVariableName$ = variableName$ End If outputString$ = outputString$ & "public property get " & setgetVariableName$ & " as " & variableType$ & NL$ outputString$ = outputString$ & Chr$(9) & setgetVariableName$ & " = me." & variableName$ & NL$ outputString$ = outputString$ & "End Property" & NL$ outputString$ = outputString$ & "public property set " & setgetVariableName$ & " as " & variableType$ & NL$ outputString$ = outputString$ & Chr$(9) & " me." & variableName$ & " = " & setgetVariableName$ & NL$ outputString$ = outputString$ & "End Property" & NL$ & NL$ End Foralldoc.Output = outputStringCall uidoc.reload

Do you have comments on this tip?

This tip was submitted to the SearchDomino.com tip library by member Mike Brown. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? and you could win a prize.

转载地址:http://hvyal.baihongyu.com/

你可能感兴趣的文章
linux ***
查看>>
豆瓣网站为什么会选择python而不是ruby
查看>>
在腾讯云服务器上体验Docker
查看>>
OpenStack Rabbit 集群实现
查看>>
我的友情链接
查看>>
mysql存储过程
查看>>
DDD(领域驱动设计)jpatable主键生成策略RBAC打造通用WEB权限
查看>>
我的友情链接
查看>>
混乱字符串的字段提取
查看>>
我的友情链接
查看>>
内核参数优化/etc/sysctl.conf
查看>>
对象标签1
查看>>
MacOS下安装MongoDB数据库
查看>>
Git常用命令
查看>>
libevent学习
查看>>
动态代理的几种方式
查看>>
Collections常用方法总结
查看>>
微信小程序
查看>>
bash变量
查看>>
知识点049-supervisor
查看>>