RTF blob field to RVF blob field
Posted: Sun Nov 18, 2012 11:00 am
Hello,
I need to convert the content of some BLOB SUB_TYPE 1 fields with RTF content to RVF and save it in BLOB SUB_TYPE 0 fields. If possible without using a form with RichViewEdit(s).
I believe there was a thread about a similar question, but it's not accessable anymore, so I would like to ask here.
So far I've tried this:
The format (colors, font settings etc.) get lost though. Probably something RVStyle related...
Can it work that way at all? What am I missing here to get it to work?
I need to convert the content of some BLOB SUB_TYPE 1 fields with RTF content to RVF and save it in BLOB SUB_TYPE 0 fields. If possible without using a form with RichViewEdit(s).
I believe there was a thread about a similar question, but it's not accessable anymore, so I would like to ask here.
So far I've tried this:
Code: Select all
function RTFToRVF_BlobFeld(RTF_Field, RVF_Field: TField; RichViewStyle: TRVStyle): boolean;
var
myRichViewStyle: TRVStyle;
myReportHelper: TRVReportHelper;
myStream: TMemoryStream;
begin
Result := false;
if assigned(RTF_Field) and assigned(RVF_Field) then begin
if (RTF_Field is TBlobField) and (RVF_Field is TBlobField) then begin
if RichViewStyle = nil then begin
myRichViewStyle := TRVStyle.Create(nil);
end
else begin
myRichViewStyle := RichViewStyle;
end;
myReportHelper := TRVReportHelper.Create(nil);
myStream := TMemoryStream.Create;
try
myReportHelper.RichView.Style := myRichViewStyle;
myReportHelper.RichView.Options := myReportHelper.RichView.Options + [rvoTagsArePChars];
TBlobField(RTF_Field).SaveToStream(myStream);
myStream.Position := 0;
if myReportHelper.RichView.LoadRTFFromStream(myStream) then begin
myStream.Clear;
myReportHelper.RichView.SaveRVFToStream(myStream, false);
myStream.Position := 0;
TBlobField(RVF_Field).LoadFromStream(myStream);
Result := true;
end;
finally
FreeAndNil(myStream);
FreeAndNil(myReportHelper);
if RichViewStyle = nil then begin
FreeAndNil(myRichViewStyle);
end;
end;
end;
end;
end;
Can it work that way at all? What am I missing here to get it to work?