Page 1 of 1

Copy content of TDBRichView into TRichEdit not complete

Posted: Thu May 19, 2016 10:18 pm
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

Re: Copy content of TDBRichView into TRichEdit not complete

Posted: Sat May 21, 2016 10:03 am
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

Posted: Sat May 21, 2016 10:53 am
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

Posted: Sat May 21, 2016 5:56 pm
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.

Posted: Sat May 21, 2016 6:10 pm
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

Posted: Sun May 22, 2016 3:31 pm
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

Posted: Sun May 22, 2016 8:38 pm
by Sergey Tkachenko
Do these editors have the same values of RVFOptions property?

Posted: Sun May 22, 2016 10:09 pm
by PioPio
Sergey Tkachenko wrote:Do these editors have the same values of RVFOptions property?
Yes, they do have the same RVFOptions property

Posted: Mon May 23, 2016 8:58 am
by Sergey Tkachenko
Save the both streams to files and send them to me to richviewgmailcom