UIDocumentやUIViewはOn Eventを使うとイベントハンドラをフックできる。
複数のビューやフォームで同じイベント処理を実施する場合は、事前に関数やオブジェクトを定義し、PostOpenなどでOn Eventを使うとよい。
例)編集可能なビューのクラス
%REM
Class objEditableVw
Description:
使い方
1.ビューでライブラリ取込
(option) - Use "objEditableVw"
2.ビューで変数宣言
(declarations) - Dim objVw as objEditableVw
3.ビューのpostopenイベントでインスタンス生成
sub PostOpen - set objVw = new objEditableVw(Source)
4.列のプロパティで編集可能にチェック
%END REM
Class objEditableVw
'Constructor
Sub New( Source As NotesUIView )
On Event InViewEdit From Source Call InViewEdit
End Sub
'Destructor
Sub Delete
End Sub
'private function
Private Sub InViewEdit(Source As NotesUIView, Requesttype As Integer,_
Colprogname As Variant, Columnvalue As Variant, Continue As Variant)
REM Define constants for request types
Const QUERY_REQUEST = 1
Const VALIDATE_REQUEST = 2
Const SAVE_REQUEST = 3
Const NEWENTRY_REQUEST = 4
REM Define variables
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim caret As String
Dim i As Integer
REM Get the CaretNoteID - exit if it does not point at a document
caret = Source.CaretNoteID
If caret = "0" Then Exit Sub
REM Get the current database and document
Set db = Source.View.Parent
Set doc = db.GetDocumentByID(caret)
REM Select the request type
Select Case Requesttype
Case QUERY_REQUEST
REM Reserved - do not use in Release 6.0
Case VALIDATE_REQUEST
REM Cause validation error if user tries to exit column with no value
If FullTrim(Columnvalue(0)) = "" Then
'Messagebox "You must enter a value",, "No value in column"
'Continue = False
End If
Case SAVE_REQUEST
REM Write the edited column view entries back to the document
For i = 0 To UBound(Colprogname) Step 1
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
Case NEWENTRY_REQUEST
REM Create document and create "Form" item
REM Write column values to the new document
Set doc = New NotesDocument(db)
Call doc.ReplaceItemValue("Form", "Main")
For i = 0 To UBound(Colprogname) Step 1
Call doc.ReplaceItemValue(Colprogname(i), Columnvalue(i))
Next
REM Save(force, createResponse, markRead)
Call doc.Save(True, True, True)
End Select
End Sub