Datenschutz

 8.0.x  8.5.x 

Bearbeitung von RichTextItems bringt Laufzeitfehler

Manfred Meise  2 Dezember 2011 08:19:49
 
Die programmatische Bearbeitung von RichText-Feldern ist Dank entsprechender LotusScript Klassen möglich, doch oftmals mühselig. So erstellten wir in diesen Tagen auf Kundenwunsch eine Schaltfläche in einer Maske, um in einem RichText Feld eine Tabelle (z.B. eine Agenda) zu erstellen. Diese funktionierte bei neuen Dokumenten wie gewünscht, jedoch nicht in Fällen, wo die Tabelle erst nach dem ersten Speichern des Dokumentes eingefügt werden sollte.

In diesen Fällen erscheinen Fehlermeldungen wir "Object Variable not set" oder auch "Type mismatch in method AssignClassInstance: AINSTANCE found, Unknown expected"
Image:Bearbeitung von RichTextItems bringt Laufzeitfehler
wenn man mit dem Body Feld der Kalendermaske mit folgendem Code:

 
Sub Click(Source As Button)
   
   Dim s                As New NotesSession
   Dim ws             As New NotesUIWorkspace
   Dim uiDoc       As NotesUIDocument
   Dim doc           As NotesDocument
   Dim body        As NotesRichTextItem
   Dim rtnav         As NotesRichTextNavigator
   
   ' - Get UI and BE document handles to current document
   Set uiDoc        = ws.CurrentDocument
   Set doc            = uiDoc.Document
   
   ' - Create or grab RT item
   If doc.IsNewNote Then
           doc.Form = "RT Tests"
           Set body = New NotesRichTextItem(doc,"Body")
   Else
           Set body = doc.GetFirstItem("Body")
   End If
   
     ' - Create a 4 column table in RT item
   Dim styles(1 To 4) As NotesRichTextParagraphStyle
   rowCount% = 5
   columnCount% = 4
   
   'Column 1
   Set styles(1) = s.CreateRichTextParagraphStyle
   styles(1).LeftMargin = 0
   styles(1).FirstLineLeftMargin = 0
   styles(1).RightMargin = RULER_ONE_CENTIMETER* 2
   
   'Column 2
   Set styles(2) = s.CreateRichTextParagraphStyle
   styles(2).LeftMargin = 0
   styles(2).FirstLineLeftMargin = 0
   styles(2).RightMargin = RULER_ONE_CENTIMETER* 17
   
   'Column 3
   Set styles(3) = s.CreateRichTextParagraphStyle
   styles(3).LeftMargin = 0
   styles(3).FirstLineLeftMargin = 0
   styles(3).RightMargin = RULER_ONE_CENTIMETER* 3
   
   'Column 4
   Set styles(4) = s.CreateRichTextParagraphStyle
   styles(4).LeftMargin = 0
   styles(4).FirstLineLeftMargin = 0
   styles(4).RightMargin = RULER_ONE_CENTIMETER* 2.5
   
   Call body.AppendTable(rowCount%, columnCount%,,,styles)
   
   ' - Populate table - the top row
   Set rtnav = body.CreateNavigator
   Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
   Call body.BeginInsert(rtnav)
   Call body.AppendText("Nr.")
   Call body.EndInsert
   Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
   Call body.BeginInsert(rtnav)
   Call body.AppendText("Thema")
   Call body.EndInsert
   Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
   Call body.BeginInsert(rtnav)
   Call body.AppendText("Erlediger")
   Call body.EndInsert
   Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
   Call body.BeginInsert(rtnav)
   Call body.AppendText("Zeit")
   Call body.EndInsert
   Call body.Update
   
   ' - Reopen document in order to load RT item into UI
   doc.SaveOptions = "0" ' make it possible to close the document without a "do you want to save" prompt.
   Call uidoc.Close(True)
   Set uidoc = ws.EditDocument(True, doc, , , , True)
   Call uidoc.Document.RemoveItem("SaveOptions")
   
End Sub

arbeitet.

Nach langer Analyse stellte ich fest, das die Ursache für den Laufzeitfehler (für mich nicht erklärbar) in der Definition der Feldhilfe
Image:Bearbeitung von RichTextItems bringt Laufzeitfehler
zu finden ist. Entfernt man diese, so wird mit

 
Set body = doc.GetFirstItem("Body")

auch das entsprechende Item gefunden.