Having problems binding class functions using On Event--anyone know why this doesn't work?

Hi all,

I have the following class in LotusScript:

Option Public

Option Declare

Const FIELD_PRESAVEEXPDATE$ = “PreSaveExpDate”

Const RESET_REPORT% = 0

Class DateChecker

m_doc As NotesDocument

m_expDT As NotesDateTime

m_preSaveExpDT As NotesDateTime



Public Sub New(Source As NotesUIDocument)

	On Event OnLoad From Source Call GetCurrentDate

	On Event OnSubmit From Source Call CheckExpDate

End Sub



Public Sub GetCurrentDate(Source As NotesUIDocument)

	Set m_doc = Source.Document

	Set m_expDT = New NotesDateTime(m_doc.SExpDate(0))

	m_doc.PreSaveExpDate = m_expDT.DateOnly

End Sub



Public Sub CheckExpDate(Source As NotesUIDocument,Continue As Variant)

	Set m_doc = Source.Document

	Set m_expDT = New NotesDateTime(m_doc.SExpDate(0))

	Set m_preSaveExpDT = New NotesDateTime(m_doc.PreSaveExpDate(0))

	If m_expDT.DateOnly = m_preSaveExpDT.DateOnly Then

		Continue = True

	Else

		m_doc.RemoveItem(FIELD_PRESAVEEXPDATE)

		m_doc.ReportRun = RESET_REPORT

		Continue = True

	End If

End Sub

End Class

In my OnLoad event, I have the following code:

Sub Onload(Source As Notesuidocument)

Dim dateChecker As New DateChecker(Source)

End Sub

When the Onload event runs, it instantiates the class, but ignores my On Event line.

Am I doing this right? Or am I missing something? Any enlightenment would be greatly appreciated.

brandt

Subject: RE: Having problems binding class functions using On Event–anyone know why this doesn’t work?

This is a little fancier than I’ve tried to do, but it occurs to me that perhaps your event registrations are working. The problem perhaps lies elsewhere.

The first problem I see is that your DateChecker object is declared locally in the form Onselect event, so when Onselect ends it is deallocated. This makes it unavailable to receive event calls. You must store the object in a global.

The second problem is that your object is registering itself to handle the Onload event, in the Onload event. Even if it still existed when the form Onload event finished, I’m not sure LotusScript would call your registered Onload handler – the opportunity may have passed.

Subject: RE: Having problems binding class functions using On Event–anyone know why this doesn’t work?

Andre,

I think I see where you are going with this–you are saying that I need to declare the instance of the class that I am using globally, and then instantiate it as part of the Initialize event or something that comes before Onload and OnSubmit?

I have since re-coded the class to work in a different way, but I discovered the On Event functionality through my Lotus blog reading, and I thought I’d give it a try.

thanks for the input.

brandt