ScaleRichView Formatting Problem

General TRichView support forum. Please post your questions here
Post Reply
pgkammath
Posts: 30
Joined: Fri Nov 24, 2017 6:16 am

ScaleRichView Formatting Problem

Post by pgkammath »

The following is the simple piece of code i am having trouble with.
Its simply print out line by line from a data source

Finaldata is the scalerichview component

My issue is that , the changes made to RvsHeading, RvsSubHeading etc in Rvstyle is not reflected in the report. Also, I find that the application, when used from other systems, shows the expected changes. I checked the fonts in my system, which is Ok. Is there anything which is fundmentally wrong. The application behaves wrongly on a development system and perfectly on user systems

Kindly help.


FinalData.RichViewEdit.Style := RvStyle1;

FinalData.Clear;

FinalData.ReadOnly := False;

FinalData.RichViewEdit.LoadRVF('C:\BMH-CURRENT\CCP\MASTER HEALTH CHECK-UP.rvf');
FinalData.RichViewEdit.Reformat;

if Trim(PatName.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<PatientName>', Trim(PatName.Text));

if Trim(PatAge.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<PatientAge>', Patgender.text + '/' + PatAge.Text);

if Trim(HospitalId.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<PatId>', HospitalId.Text);

if Trim(PatAdd1.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<Address1>', Trim(PatAdd1.Text));

if Trim(PatAdd2.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<Address2>', Trim(PatAdd2.Text));

if Trim(PatAdd3.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<Address3>', Trim(PatAdd3.Text));

if Trim(PhoneNos.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<PatientPhone>', Copy(Trim(PhoneNos.Text),1,10));

if Trim(PhoneNos.Text) <> '' then
Search_And_Replace_RV(FinalData.RichViewEdit,'<Mhcdate>', cMhcdate);

FinalData.RichViewEdit.AddTextNL(' ',rvsNormal,0,0);


FinalData.RichViewEdit.Reformat;

FinalData.RichViewEdit.AddTextNL(' ',rvsNormal,0,0);

if Trim(PresComp.Lines.Text) <> '' then begin
FinalData.RichViewEdit.AddTextNL('PRESENTING COMPLAINTS ',rvsHeading,0,0);
FinalData.RichViewEdit.AddTextNL(Trim(PresComp.Lines.Text),rvsNormal,0,0);
end;

if Trim(SurgHist.Lines.Text) <> '' then begin
FinalData.RichViewEdit.AddTextNL(' ',rvsNormal,0,0);
FinalData.RichViewEdit.AddTextNL('Surgical History',rvsHeading,0,0);
FinalData.RichViewEdit.AddTextNL(Trim(SurgHist.Lines.Text),rvsNormal,0,0);
end;

if Trim(MedHist.Lines.Text) <> '' then begin
FinalData.RichViewEdit.AddTextNL(' ',rvsNormal,0,0);
FinalData.RichViewEdit.AddTextNL('Medications',rvsHeading,0,0);
FinalData.RichViewEdit.AddTextNL(Trim(MedHist.Lines.Text),rvsNormal,0,0);
end;

....

....
FinalData.RichViewEdit.Reformat;
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ScaleRichView Formatting Problem

Post by Sergey Tkachenko »

Reformat should be used only if content is not changed (i.e. after changing margins, indents, font size).
Call Finaldata.Format instead (yes, for ScaleRichView, you should call Finaldata.Format instead of Finaldata.RichViewEdit.Format)
pgkammath
Posts: 30
Joined: Fri Nov 24, 2017 6:16 am

Re: ScaleRichView Formatting Problem

Post by pgkammath »

Thanks Sergey,
I think , I figured out from where the issue came.

This line.
FinalData.RichViewEdit.LoadRVF('C:\BMH-CURRENT\CCP\MASTER HEALTH CHECK-UP.rvf');
I am loading the RVF file.
Here I am replacing the Tags with the values. When I blocked this loading and replace process, The formatting is back properly. What could be the reason. I am attaching the RVF for reference. I created the RVF separately and saved it.

I use this for search and replace

function Search_And_Replace_RV(RichEdit: TRichViewEdit;SearchData, ReplaceText: string): Boolean;
begin
with RichEdit do begin
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
while SearchText(SearchData, [rvseoDown,rvseoWholeWord]) do InsertText(ReplaceText);
Format;
end;
end;

Regards,
Attachments
MASTER HEALTH CHECK-UP.rvf
(6.61 KiB) Downloaded 1052 times
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ScaleRichView Formatting Problem

Post by Sergey Tkachenko »

Can you explain what's exactly wrong? This code is not optimal, but it works fine for me
(the only exception is not replacing <PatientAge> because it consists of two items ('<' with font size = 9, and 'PatientAge>' with font size = 11). It can be fixed by applying the same font attributes to it, or by including rvseoMultiItem in the Options parameter of SearchText.

Otherwise, I do not see problems with formatting.

But maybe you assume that formatting (text and paragraph styles) from RVStyle1 will be used when you call AddTextNL? It's wrong: formatting from 'MASTER HEALTH CHECK-UP.rvf' will be used instead, because RVF loading replaces the existing formatting.

There are several ways to solve this problem.

1) Use

Code: Select all

Stream := TFileStream.Create('C:\BMH-CURRENT\CCP\MASTER HEALTH CHECK-UP.rvf', fmOpenRead);
FinalData.RichViewEdit.InsertRVFFromStream(Stream, 0);
Stream.Free;
With this code, existing text and paragraph formatting in RVStyle will not be replaced.

2) You can construct text styles having necessary properties in code (see this topic for examples: https://www.trichview.com/forums/viewto ... f=2&t=8537 )

PS: Do not assign FinalData.RichViewEdit.Style. The correct way for changing RVStyle is FinalData.ExternalRVStyle := RVStyle1.
PPS: Format is not needed in Search_And_Replace_RV, because InsertText reformats the changed paragraphs itself.
PPS: Using SearchText+InsertText for field replacing is very inefficient. See here for the examples that show how to do it efficiently: https://www.trichview.com/forums/viewtopic.php?f=3&t=8 . The most appropriate demo there is MailMerge-Text3, the only difference is using {} instead of <>.
pgkammath
Posts: 30
Joined: Fri Nov 24, 2017 6:16 am

Re: ScaleRichView Formatting Problem

Post by pgkammath »

Thanks Sergey.

I made the mistake as you have mentioned.
Assuming that formatting (text and paragraph styles) from RVStyle1 will be used when I call AddTextNL. Also, about
formatting from 'MASTER HEALTH CHECK-UP.rvf'.

Now everthing is fine.

Thanks once again for the explanation

Regards,
Post Reply