Page 1 of 1
Inserting paragraphs on the fly
Posted: Thu Jul 13, 2006 2:35 am
by pfsarli
I wish to process the contents of a DBRichView component and, depending on a flag, substitute certain text markers for new paragraphs while the document is being loaded.
I am trying to do this in the OnItemAction event handler. I´m not sure if this is the best place to do so, and to be honest, results are not what I want. The only way I can get a new paragraph to start is to do a PageBreakBefore on the current item. Could somebody give me an example or point me in the right direction?
Thanks
Posted: Thu Jul 13, 2006 10:01 am
by Sergey Tkachenko
Note: when you modify document in TDBRichView, the changed document will not be saved back to the field, because TDBRichView cannot do it.
If you need to save changes, use TDBRichViewEdit.
The best place to modify document in DBRichView before displaying is OnLoadDocument event. The document is loaded, but not displayed yet.
Before modifying document, please read "Valid Documents" topic in the help file, because it's very easy to create incorrect document using methods described below.
To make item i to start a new paragraph:
rv.GetItem(i).SameAsPrev := False;
To change paragraph style of item:
rv.GetItem(i).ParaNo := NewParaNo (see the rule #1 in that help topic)
Posted: Thu Jul 13, 2006 1:02 pm
by pfsarli
Sergey:
Thank you very much for your prompt reply. The processing that I wish to perform on the document is for display purposes only, the source (in the database) must remain intact.
Since we´re at it, there is another fix that I wish to perform on the document. Depending on the text to be displayed, I sometimes get orphan opening parenthesis. I need to find these parenthesis and push them to the next line (break line before, but within same paragraph) so that these opening parenthesis stay glued to the immediately following word. Just to be sure, the event to perform this would also be OnLoadDocument? And once I find the parenthesis that I wish to push down to the next line, all that would be needed would be to make the BR property (of the respective item) equal true? Once again, thank you for your help
Paulo
Posted: Thu Jul 13, 2006 1:08 pm
by Sergey Tkachenko
Yes, you can do it in the same event.
Opening parenthesis may be not at the beginning of text item. In that case, you should break text item in two (using undocumented methods).
I'll make an example tomorrow.
Posted: Fri Jul 14, 2006 12:52 pm
by pfsarli
Sergey:
I will need those examples of yours using the undocumented methods because, try as hard as I did, I couldn´t get the parenthesis trick to work...
Paulo
Posted: Fri Jul 14, 2006 4:13 pm
by Sergey Tkachenko
Posted: Mon Jul 17, 2006 2:29 am
by pfsarli
Sergey:
I downloaded your example and tested the code in my application. Your code works like a clock, but I still have one problem to solve. How can I determine the item´s line number, along with the next line´s line number? If the parênthesis is the last char on the current line, then and only then will I want to drop it to the next line along with the following item... Thanks a lot for your help (and patience)
Paulo
Posted: Mon Jul 17, 2006 2:17 pm
by Sergey Tkachenko
But line wrapping depends on window width. If you resize TRichView window, lines will be wrapped differently.
Posted: Mon Jul 17, 2006 2:33 pm
by pfsarli
Yes, you are right (of course). So my question should be: where is the best place (event) to place code that analyzes the final layout of text on the RICHVIEW control so as to make these adjustments?
Another question: how can I trigger a refresh of the current contents of the field to which my DBRichView controls is attached without having to navigate to the next or previous record?
Once again, thanks !
Paulo
Posted: Tue Jul 18, 2006 6:09 pm
by Sergey Tkachenko
where is the best place (event) to place code that analyzes the final layout of text on the RICHVIEW control so as to make these adjustments?
As I understand, you want to make changes in formatted document (only in formatted document you can get information about line wrapping).
In this case, you cannot use OnLoadDocument, because it is called before the document is formatted (and displayed).
Probably, table.AfterScroll event should work, try it.
Access to formatting information is not documented.
I'll try to explain the basics.
RichView.RVData.DrawItems is a list of TRVDrawLineInfo objects (DLines unit)
These objects represent formatting in the document.
Each non-text item corresponds to one such object.
Text item corresponds to one or more (if it is wrapped) such objects.
This object has properties:
ItemNo - index of item linked to this object
Offs - offset in this item (valid for text)
Length - length of text (valid for text)
(meaning of (ItemNo,Offs) is similar to parameters of SetSelectionBounds)
FromNewLine - true if this items starts a new line (not necessary a paragraph or <BR>, it may be a result of word wrapping)
This information is enough to determine which character is the last character in each line.
Another question: how can I trigger a refresh of the current contents of the field to which my DBRichView controls is attached without having to navigate to the next or previous record?
table.Refresh, I think.