Copy content of TDBRichView into TRichEdit not complete

General TRichView support forum. Please post your questions here
Post Reply
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Copy content of TDBRichView into TRichEdit not complete

Post by PioPio »

Hello,

I have a form with the following code:

Code: Select all

  TStrategiesExecute = class(TForm)
    RVStyle1: TRVStyle;
    RVLetterTemplate: TDBRichView;
    RVStyle: TRVStyle;
    RVActualLetter: TRichView;
  public
    function CopyTemplate: Boolean;
    ...  
  end;

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TMemoryStream;
  a,b:Integer;
  aa,bb:string;
  i:Integer;
begin
  Stream := TMemoryStream.Create;
  try
    RVLetterTemplate.SaveRTFToStream(Stream, False);
    Stream.Position := 0;
    RVActualLetter.Clear;
    RVActualLetter.LoadRTFFromStream(Stream);
    RVActualLetter.Format;
    a:= RVLetterTemplate.RVData.ItemCount;
    b := RVActualLetter.RVData.ItemCount;// here a=b
    aa:=RVLetterTemplate.RVData.GetItemTag(0);
    bb:=RVActualLetter.RVData.GetItemTag(0);// here aa is <> than bb
  finally
    Stream.Free;
  end;
end;
Why is it ? Shouldn't LoadRTFFromStream copy the data in full ?

Many thanks

Alberto
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Re: Copy content of TDBRichView into TRichEdit not complete

Post by PioPio »

PioPio wrote:Hello,

I have a form with the following code:

Code: Select all

  TStrategiesExecute = class(TForm)
    RVStyle1: TRVStyle;
    RVLetterTemplate: TDBRichView;
    RVStyle: TRVStyle;
    RVActualLetter: TRichView;
  public
    function CopyTemplate: Boolean;
    ...  
  end;

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TMemoryStream;
  a,b:Integer;
  aa,bb:string;
  i:Integer;
begin
  Stream := TMemoryStream.Create;
  try
    RVLetterTemplate.SaveRTFToStream(Stream, False);
    Stream.Position := 0;
    RVActualLetter.Clear;
    RVActualLetter.LoadRTFFromStream(Stream);
    RVActualLetter.Format;
    a:= RVLetterTemplate.RVData.ItemCount;
    b := RVActualLetter.RVData.ItemCount;// here a=b
    aa:=RVLetterTemplate.RVData.GetItemTag(0);
    bb:=RVActualLetter.RVData.GetItemTag(0);// here aa is <> than bb
  finally
    Stream.Free;
  end;
end;
Why is it ? Shouldn't LoadRTFFromStream copy the data in full ?

Many thanks

Alberto
I am still working on that and doing some tests. If I replace the code above in the following way then I get the result I want:

Code: Select all

  TStrategiesExecute = class(TForm)
    RVStyle1: TRVStyle;
    RVLetterTemplate: TDBRichView;
    RVStyle: TRVStyle;
    RVActualLetter: TRichView;
  public
    function CopyTemplate: Boolean;
    ...  
  end;

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TMemoryStream;
  a,b:Integer;
  aa,bb:string;
  i:Integer;
begin
    RVLetterTemplate.SaveRVF('abc.rtf',False);// I changed this line
    RVActualLetter.Clear;
    RVActualLetter.LoadRVF('abc.rtf');// I changed this line
    RVActualLetter.Format;
    a:= RVLetterTemplate.RVData.ItemCount;
    b := RVActualLetter.RVData.ItemCount;// here a=b
    aa:=RVLetterTemplate.RVData.GetItemTag(0);
    bb:=RVActualLetter.RVData.GetItemTag(0);// NOW AA=BB TOO ! This is the result I want
end;
It seems I am doing something wrong when I save/load the data from TMemoryStream in my previous example. Any ideas of what I am doing wrong because I really don't want to go to the "save file" route ?

Many thanks
Alberto
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Ok, the following code works:

Code: Select all

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TStream;
  a,b:Integer;
  aa,bb:string;
  i:Integer;
begin
  try
    Stream:=RVLetterTemplate.DataSource.DataSet.CreateBlobStream(RVLetterTemplate.DataSource.DataSet.FieldByName('template'),bmRead);
    RVActualLetter.Clear;
    RVActualLetter.LoadRVFFromStream(Stream);
    RVActualLetter.Format;
    a:= RVLetterTemplate.ItemCount;
    b := RVActualLetter.ItemCount;// here a=b
    aa:=RVLetterTemplate.GetItemTag(0);
    bb:=RVActualLetter.GetItemTag(0);// NOW AA=BB TOO ! This is the result I want
  finally
    Stream.Free;
  end;
end;

My question is: why isn't my initial TMemoryStream implementation working ? Can I made my initial code to work ? It looks neater to me.

Many thanks
Alberto
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the first version of your code, you used RTF (Rich Text Format). In the final version, you use RVF (RichView Format).
When you use RVF, document is the same after reloading. When you use RTF, a conversion to RTF and back is performed, and the resulting document is not exactly like the original.
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:In the first version of your code, you used RTF (Rich Text Format). In the final version, you use RVF (RichView Format).
When you use RVF, document is the same after reloading. When you use RTF, a conversion to RTF and back is performed, and the resulting document is not exactly like the original.
Thank you very much Sergey. I have amended the code following your directions and now it works. Here below the code I have at the moment for everybody's benefit.

Code: Select all

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TMemoryStream;
  a, b: Integer;
  aa, bb: string;
begin
  Result := False;
  Stream := TMemoryStream.Create;
   try
    RVLetterTemplate.SaveRVFToStream(Stream, False);
    Stream.Position := 0;
    RVActualLetter.Clear;
    RVActualLetter.LoadRVFFromStream(Stream);
    RVActualLetter.Format;
    a:= RVLetterTemplate.RVData.ItemCount;
    b := RVActualLetter.RVData.ItemCount;// here a=b
    aa:=RVLetterTemplate.RVData.GetItemTag(0);
    bb:=RVActualLetter.RVData.GetItemTag(0);// here aa is = bb
  finally
    Stream.Free;
  end;
Thank you again
Alberto
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Hello,

I have a different issue on the same procedure now.
After having copied the content from RVLetterTemplate to RVActualLetter I checked if the two contents are identical and implemented temporary Stream1 and Stream 2. After the copy, Stream1.Size is <> than Stream2.Size. Is there anything else I am missing ? Below is the code.

Code: Select all

function TStrategiesExecute.CopyTemplate: Boolean;
var
  Stream: TMemoryStream;
  Stream1: TMemoryStream;
  Stream2: TMemoryStream;
begin
  Result := False;
  Stream := TMemoryStream.Create;
   try
    RVLetterTemplate.SaveRVFToStream(Stream, False);
    Stream.Position := 0;
    RVActualLetter.Clear;
    RVActualLetter.LoadRVFFromStream(Stream);
    RVActualLetter.Format;
	
	Stream1:=TMemoryStream.Create;
    RVLetterTemplate.SaveRVFToStream(Stream1,False);
    Stream1.Position:=0;
	
	Stream2:=TMemoryStream.Create;
    RVActualLetter.SaveRVFToStream(Stream2,False);
    Stream2.Position:=0;
	//Stream1.Size is <> than Stream2.Size
	
  finally
    Stream.Free;
	Stream1.Free;
	Stream2.Free;
  end;
Many thanks
Alberto
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do these editors have the same values of RVFOptions property?
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:Do these editors have the same values of RVFOptions property?
Yes, they do have the same RVFOptions property
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Save the both streams to files and send them to me to richviewgmailcom
Post Reply