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 ?
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.
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.
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.
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;
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.