Having issue with LoadRVFFromStream

General TRichView support forum. Please post your questions here
Post Reply
Vandy1Fan
Posts: 10
Joined: Thu Jun 21, 2012 6:47 pm
Location: United States

Having issue with LoadRVFFromStream

Post by Vandy1Fan »

I am saving RVF data to a sql database in hex. I read it from the database and convert the hex to a string.
I read the string to a stream.
I call LoadRVFFromStream. The RichViewEdit is blank.

I have tried this with both a TStringStream and a TMemoryStream.
Here is the code.


procedure TfrmMain.FormShow(Sender: TObject);
var
vStream:TStringStream;
vStr:string;
begin
RichViewEdit1.Clear;
try
vStream:=TStringStream.Create;
vStr:=HexToString(adoquery1.FieldByName('RTFData').asstring);
vStream.WriteString(vStr);
vStream.Position:=0;
if not RichViewEdit1.LoadRVFFromStream(vStream) then
ShowMessage('Unable to load from stream');

finally
Freeandnil(vStream);
end;
end;
Vandy1Fan
Posts: 10
Joined: Thu Jun 21, 2012 6:47 pm
Location: United States

Here is how I'm loading the rvf to the database

Post by Vandy1Fan »

procedure TfrmMain.actSaveExecute(Sender: TObject);
var
vStream:TStringStream;
xStream:TMemoryStream;
vStr:string;
vSL:TStringList;
begin
try
vSL:=TStringList.Create;
vStream:=TStringStream.Create;
xStream:=TMemoryStream.Create;
RichViewEdit1.SaveRVFToStream(xStream, false);
xStream.Position:=0;
vStream.LoadFromStream(xStream);
vStr:=vStream.ReadString(vStream.Size);

with ADOQuery1 do
begin
if active then
active:=false;
with SQL do
begin
Clear;
Add('select RTFData from TestRTF');
end;
Open;
Edit;
FieldByName('RTFData').AsString:=StringToHex(vStr);
Post;
Close;
end;
finally
Freeandnil(vSL);
Freeandnil(vStream);
Freeandnil(xStream);
end;
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please save the value in vStr (before calling LoadRVFFromStream) to a file and send this file to me (richviewgmailcom)
Vandy1Fan
Posts: 10
Joined: Thu Jun 21, 2012 6:47 pm
Location: United States

File sent

Post by Vandy1Fan »

I have emailed you the file.

I found a way around it by using the DBRichViewEdit.

I will be officially registering later today.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Answered by email
Vandy1Fan
Posts: 10
Joined: Thu Jun 21, 2012 6:47 pm
Location: United States

Here is what I did

Post by Vandy1Fan »

I took your example program ActionTestRibbon.
I created a SQLServer table called TestRTF with 1 field called RTFData. RTFData is a varchar(MAX).

I created a new TAction in the Action Manager.

Here is the onExecute for the action.

Code: Select all

procedure TfrmMain.actSaveExecute(Sender: TObject);
var
  vStream:TStringStream;
  xStream:TMemoryStream;
  vStr:string;
  vSL:TStringList;
begin
  try
  vSL:=TStringList.Create;
  vStream:=TStringStream.Create;
  xStream:=TMemoryStream.Create;
  RichViewEdit1.SaveRVFToStream(xStream, false);
  xStream.Position:=0;
  vStream.LoadFromStream(xStream);
  vStr:=vStream.ReadString(vStream.Size);
  with ADOQuery1 do
  begin
    if active then
      active:=false;
    with SQL do
    begin
      Clear;
      Add('select RTFData from TestRTF');
    end;
    Open;
    Edit;
    FieldByName('RTFData').AsString:=StringToHex(vStr);
    Post;
    Close;
  end; 
  finally
    Freeandnil(vSL);
    Freeandnil(vStream);
    Freeandnil(xStream);
  end;
end;
This saves the data to the database in hex. This must be done because of the /0 (ascii 0) characters that are in the data.

After saving I exit the program. When I restart the program, I reload the data from the database.

Code: Select all

procedure TfrmMain.FormShow(Sender: TObject);
var
  vStream:TStringStream;
  xStream:TMemoryStream;
  vTemp:TextFile;
  Inserted:boolean;
  vStr:string;
  vSL:TStringList;
begin
  Inserted:=false;
  with AdoQuery1 do
  begin
    if active then
      active:=false;
      with SQL do
      begin
        Clear;
        Add('select RTFData from TestRTF');
      end;
      Open;
      try
        vSL:=TStringList.Create;
        vStream:=TStringStream.Create;
        RichViewEdit1.Clear;
        xStream:=TMemoryStream.Create;
        xStream.Position:=0;
        vStr:=HexToString(FieldByName('RTFData').asstring);
        AssignFile(vTemp, 'temprvf.rvf');
        Rewrite(vTemp);
        writeln(vTemp, vStr);
        Flush(vTemp);
        CloseFile(vTemp);
        // tried this as a work-around
        rvActionOpen1.LoadFile(RichViewEdit1, 'temprvf.rvf', ffiRVF);
        // this did not work
        vStream.WriteString(vStr);
        vStream.SaveToStream(xStream);
        xStream.WriteBuffer(Pointer(vStr)^, Length(vStr));
        vStream.WriteString(vStr);
        vStream.Position:=0;
        TRVYesNoAuto.rvynaAuto
        RichViewEdit1.LoadFromStream(vStream,rvynaAuto);
        if not RichViewEdit1.LoadRVFFromStream(vStream) then
                 ShowMessage('Unable to load from stream');
      finally
        Freeandnil(vStream);
        Freeandnil(xStream);
        Freeandnil(vSL);
      end;  
    end;

  end;
end;



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

Post by Sergey Tkachenko »

In your example, the problem is in incorrect RVF record for an image.
It does not look like a document corruption, it looks like this picture was saved wrong.
So the problem may manifest itself only on specific data. In order to find the reason of this problem, I need to know how this picture was added to the document, and which properties of this picture item were assigned and how.
Vandy1Fan
Posts: 10
Joined: Thu Jun 21, 2012 6:47 pm
Location: United States

Post by Vandy1Fan »

I'm using the TDBRichViewEdit and having no issues.
Post Reply