Contents of RichViewEdit changes when printing

General TRichView support forum. Please post your questions here
Post Reply
Eugene Kruglov
Posts: 9
Joined: Mon Jul 02, 2007 9:07 pm
Location: Perm, Russia

Contents of RichViewEdit changes when printing

Post by Eugene Kruglov »

Hi, Sergey,

Your help is needed again. In my application I have, on printing, to replace controls' images as they look with text they contain. The problem is that when using RVPrint component's internal RV property the actual contents of RichViewEdit is affected, i.e. controls are replaced with text. How to do that contents of RichviewEdit remain unaffected?

This is a code example:

procedure TfrmMain.ToolButton4Click(Sender: TObject);
var i, ATag: integer;
AName, S: string;
ACtrl: TControl;
AVAlign: TRVVAlign;
begin
RVPrint1.AssignSource(RVEdit);
for i:= 0 to RVPrint1.rv.ItemCount - 1 do
begin
if RVPrint1.rv.GetItem(i).StyleNo <> rvsComponent then Continue;
RVPrint1.rv.GetControlInfo(i, AName, ACtrl, AVAlign, ATag);
RVPrint1.rv.GetItem(i).StyleNo:= 0;
if ACtrl is TDBEditEh then RVPrint1.rv.SetItemTextA(i, TDBEditEh(ACtrl).Text)
else
RVPrint1.rv.SetItemTextA(i, 'Text Example!');
end;
RVPrint1.FormatPages(rvdoAll);
rvActionPrintPreview1.Execute;
end;

Best regards, Eugene Kruglov
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's not possible, because TRVPrint.rv does not have its own items, it uses items from TCustomRichView assigned in AssignSource method.

You need to create a new of TRichView (hidden), copy document to it, do modifications, then print this hidden TRichView.
Eugene Kruglov
Posts: 9
Joined: Mon Jul 02, 2007 9:07 pm
Location: Perm, Russia

Post by Eugene Kruglov »

Sergey,

Sorry, I am probably stupid, but your advice did not help. I create TRichViewEdit, fill it with contents of another TRichViewEdit, then try to 'process' it (i.e. replace controls with text). When I change the text in the control the preview seems not to change at all!

Code fragment (sorry for large size!):

function TfrmMain.CreateTemporaryPrintRichViewEdit(Source: TRichViewEdit): TRichViewEdit;

procedure ReplaceItemText(RichView: TRichViewEdit; ItemNo: integer; NewText: string);
var S: string;
begin
S:= NewText;
ReplaceSymbols(S, #13, '');
ReplaceSymbols(S, #10, '');
RichView.GetItem(ItemNo).StyleNo:= 0;
RichView.SetItemTextA(ItemNo, S)
end;

var i, ATag: integer;
AName: string;
ACtrl: TControl;
AVAlign: TRVVAlign;
MemStream: TMemoryStream;
//NewStyle: TRVStyle;
begin
{with RVPrint do
begin
LeftMarginMM:= 0;
RightMarginMM:= 0;
PreviewCorrection:= true;
end;}
if FindComponent('PrintRVEdit') <> nil then PrintRVEdit:= TRichViewEdit(FindComponent('PrintRVEdit')) else
begin
PrintRVEdit:= TRichViewEdit.Create(Self);
PrintRVEdit.Name:= 'PrintRVEdit';
with PrintRVEdit do
begin
Visible:= false;
Style:= TRVStyle.Create(Self);
Color:= clWindow;
RVFOptions:= [rvfoSavePicturesBody, rvfoIgnoreUnknownCtrls, rvfoSaveBinary, rvfoSaveBack,
rvfoLoadBack, rvfoSaveTextStyles, rvfoSaveParaStyles, rvfoSaveLayout, rvfoLoadLayout,
rvfoSaveDocProperties, rvfoLoadDocProperties];
Options:= [rvoAllowSelection, rvoScrollToEnd, rvoShowPageBreaks, rvoTagsArePChars, rvoAutoCopyText,
rvoAutoCopyRVF, rvoAutoCopyImage, rvoAutoCopyRTF, rvoFormatInvalidate, rvoDblClickSelectsWord,
rvoRClickDeselects,rvoFastFormatting];
OnRVFControlNeeded:= RVEditRVFControlNeeded;
Parent:= Self;
end;
end;
with PrintRVEdit do
begin
MemStream:= TMemoryStream.Create;
try
Source.SaveRVFToStream(MemStream, false);
MemStream.Position:= 0;
Clear;
LoadRVFFromStream(MemStream);
Format;
for i:= 0 to ItemCount - 1 do
begin
if GetItem(i).StyleNo <> rvsComponent then Continue;
GetControlInfo(i, AName, ACtrl, AVAlign, ATag);
if not (ACtrl is TDBGridEh) then ReplaceItemText(PrintRVEdit, i, '(???)'); //первоначальное значение
if ACtrl is TDBEditEh then ReplaceItemText(PrintRVEdit, i, (ACtrl as TDBEditEh).Text);
if ACtrl is TDBLookupComboboxEh then ReplaceItemText(PrintRVEdit, i, TDBLookupComboboxEh(ACtrl).Text);
if ACtrl is TDBNumberEditEh then ReplaceItemText(PrintRVEdit, i, TDBNumberEditEh(ACtrl).Text);
if ACtrl is TDBDateEdit then ReplaceItemText(PrintRVEdit, i, TDBDateEdit(ACtrl).Text);
if ACtrl is TRxCalcEdit then ReplaceItemText(PrintRVEdit, i, TRxCalcEdit(ACtrl).Text);
if ACtrl is TDBCheckBoxEh then ReplaceItemText(PrintRVEdit, i, YesNo[Integer(TDBCheckBoxEh(ACtrl).Checked)]);
if ACtrl is TLabel then ReplaceItemText(PrintRVEdit, i, TLabel(ACtrl).Caption);
if ACtrl is TEdit then ReplaceItemText(PrintRVEdit, i, TEdit(ACtrl).Text);
if ACtrl is TMemo then ReplaceItemText(PrintRVEdit, i, TMemo(ACtrl).Text);
//if ACtrl is TCheckBox then ReplaceItemText(PrintRVEdit, i, TCheckBox(ACtrl).Text);
if ACtrl is TRadioButton then ReplaceItemText(PrintRVEdit, i, YesNo[Integer(TRadioButton(ACtrl).Checked)]);
if ACtrl is TComboBox then ReplaceItemText(PrintRVEdit, i, TComboBox(ACtrl).Text);
//if ACtrl is TButton then ReplaceItemText(PrintRVEdit, i, TButton(ACtrl).Text);
//if ACtrl is TBitButton then ReplaceItemText(PrintRVEdit, i, TBitButton(ACtrl).Text);
//if ACtrl is TSpeedButton then ReplaceItemText(PrintRVEdit, i, TSpeedButton(ACtrl).Text);
if ACtrl is TMaskEdit then ReplaceItemText(PrintRVEdit, i, TMaskEdit(ACtrl).Text);
//if ACtrl is TShape then ReplaceItemText(PrintRVEdit, i, TShape(ACtrl).Text);
if ACtrl is TRadioGroup then ReplaceItemText(PrintRVEdit, i, TRadioGroup(ACtrl).Caption + ': ' + TRadioGroup(ACtrl).Items.Strings[TRadioGroup(ACtrl).ItemIndex]);
if ACtrl is TDBDateTimeEditEh then ReplaceItemText(PrintRVEdit, i, TDBDateTimeEditEh(ACtrl).Text);
if ACtrl is TDBComboBoxEh then ReplaceItemText(PrintRVEdit, i, TDBComboBoxEh(ACtrl).Text);
end;
Format;
finally
MemStream.Free;
end;
end;
Result:= PrintRVEdit;
end;


Another accompanying question: why sometimes after creating TRichViewEdit at runtime it reacts only to BackSpace key (i.e. text is deleted) but does not do to Delete key? I can't understand what it depends on...

Awaiting reply, Eugene
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Can you send me a simple project to test?
Eugene Kruglov
Posts: 9
Joined: Mon Jul 02, 2007 9:07 pm
Location: Perm, Russia

Post by Eugene Kruglov »

Hi, Sergey!

Sorry for my stupidity, I have done it! I've forgotten that when I perform the SaveToStream/LoadFromStream actions all my controls are copied only as their text representations and restored in OnRVFControlNeeded event handler. Hence, they (after copyiing) can not reflect the changes made to original controls.

The another problem was really foolish: Delete did not work because it was implemented as shortcut in main menu :D

Best regards, Eugene.
Thank you for your work.
Post Reply