How to create NotesRichTextItem instance?

I want to have a function in a library, which should return a NotesRichTextItem class. I need to create a temporary NotesRichTextItem instance in the body of this function.

Is it possible to create a temporary instance in only in a memory?

Because the constructor expects a document instance:

Set notesRichTextItem = New NotesRichTextItem( notesDocument, name$ )

This means, that to be able to create a new RT instance, I have to pass the notesDocument in the function arguments, which doesn’t seem to be a nice way how to do it …

I want the RT only in that function. I don’t want any relationship between document here …

Is it possible?

Subject: How to create NotesRichTextItem instance?

And another question …

If I create the temporary RTItem instance inside a function body (on a certain document) how can I remove this RTItem from a document with a possibility to return it from a function?

Subject: RE: How to create NotesRichTextItem instance?

You can create a tmpdoc in your function that would contain you RTF.

set TmpDoc = ThisDB.CreateDocument

set your RTF based on tmpdoc and remove tmpdoc before the function is done.

To remove an item: call doc.removeitem(“Itemname”)

or

while doc.hasitem(“itemname”

call doc.removeitem(“itemname”)

End While

You need to explain at a higher level what you are trying to accomplish, not enought detail to answer all your questions.

Subject: RE: How to create NotesRichTextItem instance?

Hi Guys,

thx for your responses …

Tom,

If I create a tempDoc in my function body, I also need to delete this document somewhere (for me the only way is in the same function body). How can I return the NotesRichTextItem from the function then? If I delete the doucment in the function, the RT reference will also be gone …

Subject: RE: How to create NotesRichTextItem instance?

Ah, now I understand what you are asking.

You might be able to write your own RTF class - have never done it for RTF but it might be feasible.

If not, then don’t use a function becuase the reference will be gone when you remove the tmpdoc.

Subject: If you are going to return it, it must exist on a NotesDocument passed in

If not, the value would be “garbage collected” anyway. Can you explain further what you want to do?

Subject: RE: If you are going to return it, it must exist on a NotesDocument passed in

Hi Ben,

All I want to achieve is something like this:

Function BuildRTProgramatically(doc As NotesDocument) As NotesRichTextItem

Dim tempRT As notesrichtextitem

Set tempRT = doc.CreateRichTextItem(doc,"itemName")



'here i build the tempRT programatically



BuildRTProgramatically = tempRT

End Function

So this means, that if I return the tempRT, it will stay in the document.

Later on, I will use this tempRT as a parameter for a second function, which will mail the content of this RT to a user …

Sub MailRT(richTextToMail)

'mail the rich-text here

End Sub

Actually, the first function builds only a RT (collects some information from a document), which should be mailed with the second function (something like report notification).

That’s all … I wonder, where is the best place to get rid of the tempRT, which is still stored in the document …

Subject: RE: If you are going to return it, it must exist on a NotesDocument passed in

The function BuildRTProgramatically you specified will work because the NotesDocument container persists.

Instead of passing around a NotesRichTextItem and having to store it in the NotesDocument that is used as its source, have you considered creating a temporary NotesDocument to serve as the container for the RT?

This way you can just discard it when you’re done.

You can also modify your functions such as MailRT to accept a NotesDocument instead and copy the RTItem from it.

Subject: RE: If you are going to return it, it must exist on a NotesDocument passed in

Ok,

I will create a temporary document as a container and I will discard this document later on …

Thx for your responses …

Juraj

Subject: like I mentioned 8 posts ago.

Subject: It is far better to work with the NotesDocument than with the NotesRichTextItem

The reason is that a rich text field does not fully encapsulate the rich text data. To give three examples of data not stored inside the rich text, and thus not really part of the NotesRichTextItem, you have:

Font information is stored in $Fonts item. Copying the rich text without the appropriate $Fonts item will lose all custom fonts (meaning anything other than Default Serif, Default Sans Serif, etc.) since the rich text itself simply contains an offset to the font table, not the fonts themselves.

Link information is sometimes stored in the $Links item. This may not be a problem in your scenario, depending on what you are doing to build the rich text, but doclink, viewlink, dblink and anchor link information is often stored inside the $Links and only referenced by offset, like the fonts, in the rich text item.

File information is stored in $File items. If you have any file attachments, the actual attachments are stored separated and referenced by object decriptors which are in the $File items.

There are more, but these are the most obvious and explicit references outside the original rich text item, so you are definitely better off passing around a temporary document than a temporary rich text field. You don’t even have to have it fully populated, but it is a good idea to give it a form name, even if it is not a form that exists in that db. I tend to use:

Set newdoc = New NotesDocument(db)

newdoc.Form = “TempForm”

and then work from there.

Subject: RE: It is far better to work with the NotesDocument than with the NotesRichTextItem

Ben,

these informations are definitelly usefull for me !!! At least the 3’th one …

Now I see, why I am not able to send and email with an attachment (I always receive the ‘Notes item not found’ error). I think, this has something to do with this …

Thx

Usefull !!!

Subject: RE: How to create NotesRichTextItem instance?

The RTItem cannot exist outside of its container, the NotesDocument.