Page 1 of 1

Save and restore left/right margin?

Posted: Mon Apr 30, 2012 1:44 pm
by Joe
Windows 7, Delphi 2010, RichView 13.8

Please don't beat me, but I can't get it run:

In a form there is a TDBRichViewEdit and a TRVRuler. Everything works fine. When the user moves the ruler, left and/or right margin is set and the text in the TDBRichViewEdit formatted accordingly.

In the RVFOptions the rvoSaveLayout and rvoLoadLayout properties are checked to True.

After the record is saved to the database and loaded again the left and right margins are lost.

I searched this forum and found several things like
RVRuler1.UpdateRulerMargins in the RVAControlPanel1MarginsChanged(...) event - but this event is never fired
or
TDBRichViewEdit1.Format

Nothing of these helps.

What has to be done to save and load the formerly set ruler margins?


---

Another thing regarding the ruler:
Say, for getting a real imagination on how a later print output would look like, the right margin is set at 18 cm. Now, when sizing the window horizontally the right margin of the ruler also moves, and also the text. How can the margin be fixed to the desired position, independantly of widening the window size?

Best regards
Joe

Posted: Tue May 01, 2012 7:24 pm
by Sergey Tkachenko
1) In my test, the ruler works without any additional code.
Can you send me a simple project reproducing this problem?

2) Exclude rvoClientTextWidth from DBRichViewEdit.Options.
Assign DBRichViewEdit.MinTextWidth and MaxTextWidth.
For example, for 18 cm:

Code: Select all

  DBRichViewEdit1.MinTextWidth := Round(18 * Screen.PixelsPerInch / 2.54)-DBRichViewEdit1.LeftMargin-DBRichViewEdit1.RightMargin;
  DBRichViewEdit1.MaxTextWidth := DBRichViewEdit1.MinTextWidth;
Note 1: if rvoSaveLayout and rvoLoadLayout in RVFOptions, MinTextWidth and MaxTextWidth are saved with the document, like margins.
Note 2: To assign default values (of MinTextWidth, MaxTextWidth, margins, others) use OnNewDocument event.

Posted: Wed May 02, 2012 10:35 am
by Joe
Hello Sergey,

I will prepare a test project and send it to you...

Thank you
Joe

Posted: Sun May 06, 2012 11:58 am
by Joe
God bless Sergey!

Due to his explanations it came out that the database field type must (and can) contain only Unicode, which makes it impossible to store an odd number of bytes. This caused the problem.

Who ever runs into a similar problem:
In a MS Access database: don't use field type "Memo"
In a MS SQL Server database: don't use field type "NText" -> use Varbinary(max) instead.

Thank you, Sergey!

Posted: Sun May 06, 2012 7:21 pm
by Sergey Tkachenko
When you used "Unicode memo" field type, data were saved as RTF, not RVF.
In RTF, TRichView cannot save margins (RichView.LeftMargin, TopMargin, etc.)
(if you need to store page margins, you can use DocParameters property; but these are different margins: page margins are usually much larger than margins on the screen).