Page 1 of 1

TSRichViewEdit doesn't save/load controls

Posted: Sat Aug 05, 2017 12:09 pm
by elGringo
Having TSRichViewEdit. Inserting control like this

Code: Select all

SRichViewEdit.RichViewEdit.InsertControl('',scaleReportPanel,rvvaAbsMiddle);
updating DB like this

Code: Select all

...
         // blob

                 SRichViewEdit.RVHeader.SaveRVFToStream(msHeader,false);
                 SRichViewEdit.RichViewEdit.SaveRVFToStream(msBody,false);
                 SRichViewEdit.RVFooter.SaveRVFToStream(msFooter,false);

                TBlobField(FieldByName('blobContentHeader')).LoadFromStream(msHeader);
                TBlobField(FieldByName('blobContentBody')).LoadFromStream(msBody);
                TBlobField(FieldByName('blobContentFooter')).LoadFromStream(msFooter);

                if ApplyUpdates<>0 then raise Exception.Create(RowError.Message);
...
loading content like this...

Code: Select all

...
                TBlobfield(FieldByName('blobContentHeader')).SaveToStream(msHeader);
                msHeader.Position:=0;
                SRichViewEdit.RVHeader.LoadFromStream(msHeader,rvynaNo);
                SRichViewEdit.RVHeader.ReformatAll;

                TBlobfield(FieldByName('blobContentBody')).SaveToStream(msBody);
                msBody.Position:=0;
                SRichViewEdit.RichViewEdit.LoadFromStream(msBody,rvynaNo);
                SRichViewEdit.RichViewEdit.ReformatAll;

                TBlobfield(FieldByName('blobContentFooter')).SaveToStream(msFooter);
                msFooter.Position:=0;
                SRichViewEdit.RVFooter.LoadFromStream(msFooter,rvynaNo);
                SRichViewEdit.RVFooter.ReformatAll;

...
Text saved well - controls disappearing.... why?

Re: TSRichViewEdit doesn't save/load controls

Posted: Sat Aug 05, 2017 12:14 pm
by Sergey Tkachenko
Classes of all controls inserted in the editor must be registered.
Call one time, before the first loading:

Code: Select all

RegisterClasses([TEdit, TButton]);
(for all classes of used controls)

Re: TSRichViewEdit doesn't save/load controls

Posted: Sat Aug 05, 2017 12:15 pm
by elGringo
Sorry for interrupting, not attentive today, just needed to register class...
RegisterClass(TScaleReportPanel);

Re: TSRichViewEdit doesn't save/load controls

Posted: Sat Aug 05, 2017 12:17 pm
by elGringo
And else... is it normal approach to have 3 fields for header, body and footer? Or it could be just one which is pointed id DataField property of TDBSRichViewEdit

Re: TSRichViewEdit doesn't save/load controls

Posted: Sat Aug 05, 2017 7:55 pm
by Sergey Tkachenko
You do not 3 fields. SRichViewEdit.RichViewEdit.SaveRVFToStream saves the whole document, including header and footer.

Saving:

Code: Select all

SRichViewEdit.RichViewEdit.SaveRVFToStream(msBody,false);
TBlobField(FieldByName('blobContentBody')).LoadFromStream(msBody);
Loading:

Code: Select all

TBlobfield(FieldByName('blobContentBody')).SaveToStream(msBody);
msBody.Position:=0;
SRichViewEdit.RichViewEdit.LoadFromStream(msBody,rvynaNo);
SRichViewEdit.Format;
Please note that in the new version, there are not 2 but 6 headers and footers, stored in Subdocuments property. But all of them are saved and loaded by the code above.