Openening a RVF file

General TRichView support forum. Please post your questions here
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Openening a RVF file

Post by Gismo »

Hello proffesionals,

there is a bit of text inside a RVF file i want to have shown in Memo in delphi.
Also in this file are some images. But these images dont want to have shown.
Does anyone know if this is possible? And maybe have the code to do so? I got a RVF example file here and can send it to you if you need it.

With kind regards,

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

Post by Sergey Tkachenko »

You cannot show RVF file without loading it in RichViewEdit (using LoadRVF method). Then you can export it to TMemo.

For Delphi 2009 or newer:

Code: Select all

var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  RichViewEdit1.SaveTextToStreamW('', Stream, 80, False, False);
  Stream.Position := 0;
  Memo1.Lines.LoadFromStream(Stream, TEncoding.Unicode);
  Stream.Free;
end;
For older versions of Delphi:

Code: Select all

var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  RichViewEdit1.SaveTextToStream('', Stream, 80, False, False);
  Stream.Position := 0;
  Memo1.Lines.LoadFromStream(Stream);
  Stream.Free;
end;
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

I still got a little problem since i want to use it in a while loop with over 6000 RVF files and place all the text of all the rvf's with additional text into the memo. But it seems te rewrite the memo and ends with a Eaccessviolation.
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

The problem is ound in the RVF file seems to be a image. Does anyone know how i could remove the images automaticly?
Sergey Tkachenko
Site Admin
Posts: 17572
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

There should be no access violations.
Can you post your code?
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

Code: Select all

 try with table1 do begin {table with 6000 records}
table1.open;  
     while not table1.eof do

       {rvf file that matches a variable of the table}
       richviewedit1.Clear;
       richviewedit1.Style := rvstyle1;
       if FileExists(filename) then begin
       richviewedit1.LoadRVF(filename);
       end;
       richviewedit1.Format;


       Stream := TMemoryStream.Create;
       RichViewEdit1.SaveTextToStream('', Stream, 80, False, False);      
      {^seems to cause the eaccessviolation}
       Stream.Position := 0;
       memo1.lines.add(text);
       Memo1.Lines.LoadFromStream(Stream, TEncoding.Unicode); 
       memo1.lines.add(text);

       Stream.Free;

       memo1.Lines.add('---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------')

table1.next; 
end;
finally
 if Memo1.Lines.Count > 0 then
      Memo1.Lines.Delete(Memo1.Lines.Count - 1 );


   table1.filtered := false;
   table1.close;
end;
'

i tried to copy the code that mathers from my code so might be that i miss a end or something. In anycase it seems tat the loading the RVF goes ok since i checked that myself.

Though it seems it cant put it into a stream. I think this could be cause it contains a picture.

This isnt much of a problem since i need the text without pictures anyway. I just dont know yet how to remove the pictures from the richviewedit.
Sergey Tkachenko
Site Admin
Posts: 17572
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If you use LoadFromStream(Stream, TEncoding.Unicode), you need to save using SaveTextToStreamW instead of SaveTextToStream.

Did it help?
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

to bad i cant test it out now. but does this saves it in the stream without the images? since i need to remove those images in the end anyway :)
Sergey Tkachenko
Site Admin
Posts: 17572
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It saves as a plain text, without images or formatting.
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

I tried it but it didnt work out sadly. Though i managed to get all the code causing the eaccessviolation error in a single button click for testing. If needed i could give the file that might be causing the error. ill keep on tring to find the error. i posted the button code below.

Code: Select all


var
i: integer;
mychar: char;
Stream: TMemoryStream;
begin
richviewedit1.Clear;
richviewedit1.Style := rvstyle1;
richviewedit1.LoadRVF('c:\memo2_4796.rvf');
richviewedit1.Format;
Stream := TMemoryStream.Create;
RichViewEdit1.SaveTextToStreamw('', Stream, 80, False, False);
Memo1.Lines.LoadFromStream(Stream);
Stream.Position := 0;
memo1.Lines.add('---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------');
stream.Free;

end;
I still get the error on the save to stream part. If needed i can provide the file that could be causing it. Ill keep looking to solve the problem myself aswel.
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

im using delphi 7
Sergey Tkachenko
Site Admin
Posts: 17572
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Is it possible to reproduce this problem in a sample project?
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

i hope this is what you mean with reproduce in a sample project.
I now made a form with 2 buttons 1 memo 1 richviewedit and a rvstyle.
button1 loads the file
button2 transfers the file to the memo causing a eaccessviolation error
the code looks like this

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, RVScroll, RichView, RVEdit, RVStyle;

type
  TForm1 = class(TForm)
    RichViewEdit1: TRichViewEdit;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    RVStyle1: TRVStyle;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

richviewedit1.Clear;
richviewedit1.Style := rvstyle1;
richviewedit1.LoadRVF('c:\artikels.db_memo2_220.rvf');
RichViewedit1.DeleteUnusedStyles(True, True, True);
richviewedit1.Format;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
RichViewEdit1.SaveTextToStreamw('', Stream, 80, False, False);
Stream.Position := 0;
memo1.Lines.LoadFromStream(stream);
stream.Free;
end;

end.
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

i tried it with the W after savetostream but it ended up with only passing me the first letter of the text (on a rvf file that doesnt have the error) also i found a couple of more files also having this problem they all have the same thing in commen and that is that there is a table or a picture or anything like that present.
Gismo
Posts: 11
Joined: Tue Feb 21, 2012 2:32 pm

Post by Gismo »

seems like i have found a selution by changing
RichViewEdit1.SaveTextToStream('', Stream, 80, False, False);
to
RichViewEdit1.SaveTextToStream('', Stream, 80, False, true);
i should read the parameters better before i use them :). thanks for your time helping a delphi starter :D
Post Reply