Page 1 of 2
TRichViewXML : SaveToStream ... LoadFromStream
Posted: Fri Jan 23, 2009 11:08 am
by jclaes
Hi,
I'm trying to copy the data from one RichViewEdit to another using RichViewXML.SaveToStream / .. LoadFromStream.
The destination RVE stays empty . How come ??
procedure TForm1.Button1Click(Sender: TObject);
var
aStream : TStringStream ;
aString : String ;
T: TXMLTree;
MainRoot, DocRoot: TXMLTag;
begin
// SaveToStream
T := TXMLTree.Create(RichViewXML1.Encoding);
try
T.Items.AddTag(RichViewXML1.RootElement, T, T);
MainRoot := T.Items[0];
MainRoot.Items.AddTag('Data', T.Items[0], T);
DocRoot := MainRoot.Items[MainRoot.Items.Count-1];
RichViewXML1.RichView := RichViewEdit1;
RichViewXML1.SaveToXML(DocRoot);
aStream := TStringStream.Create('') ;
T.SaveToStream(aStream,true);
finally
T.Free;
end;
// LoadFromStream
T := TXMLTree.Create(RichViewXML1.Encoding);
try
T.LoadFromStream(aStream);
RichViewXML2.RichView := RichViewEdit2;
MainRoot := T.Items.FindTagOfName(RichViewXML2.RootElement);
if MainRoot<>nil then
begin
DocRoot := MainRoot.Items.FindTagOfName('Data');
if DocRoot<>nil then
begin
RichViewXML2.LoadFromXML(DocRoot);
end;
end;
finally
T.Free;
end;
RichViewEdit2.Format ;
end;
Posted: Fri Jan 23, 2009 3:11 pm
by Ar4i
To make your code more readable warp it in CODE tags.
To solve your problem you can try using InsertXXXFromStream instread of LoadFromXXX. At least thi method works fine with not XML RichView components.
Posted: Fri Jan 23, 2009 4:06 pm
by jclaes
Hi,
When I use the InsertFromStream i get a 'no root element error'
[/code]
Posted: Fri Jan 23, 2009 7:11 pm
by Sergey Tkachenko
Try setting aStream.Position := 0 before loading from this stream.
Posted: Mon Mar 23, 2009 2:09 pm
by jclaes
Sorry but still not working.
here is the code
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
aStream : TStringStream ;
aString : String ;
T: TXMLTree;
MainRoot, DocRoot: TXMLTag;
begin
// SaveToStream
T := TXMLTree.Create(RichViewXML1.Encoding);
try
T.Items.AddTag(RichViewXML1.RootElement, T, T);
MainRoot := T.Items[0];
MainRoot.Items.AddTag('Data', T.Items[0], T);
DocRoot := MainRoot.Items[MainRoot.Items.Count-1];
RichViewXML1.RichView := RichViewEdit1;
RichViewXML1.SaveToXML(DocRoot);
aStream := TStringStream.Create('') ;
T.SaveToStream(aStream,true);
finally
T.Free;
end;
// LoadFromStream
aStream.Position := 0 ;
RichViewXML2.InsertFromStream(aStream);
T := TXMLTree.Create(RichViewXML1.Encoding);
try
T.LoadFromStream(aStream);
RichViewXML2.RichView := RichViewEdit2;
MainRoot := T.Items.FindTagOfName(RichViewXML2.RootElement);
if MainRoot<>nil then
begin
DocRoot := MainRoot.Items.FindTagOfName('Data');
if DocRoot<>nil then
begin
RichViewXML2.InsertFromStream(aStream);
end;
end;
finally
T.Free;
end;
RichViewEdit2.Format ;
end;
InsertFromStreamEd
Posted: Wed Sep 21, 2011 8:27 am
by arnfinn
Hi!
I have the same problem. The destenation is empty.
Code:
Source.SaveRTFToStream(Stream, False);
Stream.Position := 0;
stream.SaveToFile('C:\streamtest.txt');
Stream.Position := 0;
Dest.InsertRTFFromStreamEd(Stream);
Dest.Format;
Posted: Wed Sep 21, 2011 9:36 am
by Sergey Tkachenko
Please send a sample project to reproduce.
(PS: Format is not needed after InsertRTFFromStreamEd)
RichView
Posted: Wed Sep 21, 2011 11:29 am
by arnfinn
Hi!
I hvae a sample file. Wher do I send it??
Arnfinn.
Posted: Wed Sep 21, 2011 1:12 pm
by arnfinn
Her is the code. I have made a DBRichView and the purpose is to copy from one to the other with the help of stream. I see that the stream has data butt the destination is empty. it is the line
Code: Select all
Dest.InsertRTFFromStreamEd(Stream);
that is the problem. Dest is empty.
Can you pleas help?
Code: Select all
procedure TForm1.cxButton2Click(Sender: TObject);
var
ItemNo,
Offset: Integer;
Stream: TMemoryStream;
Source,
Dest: TDBRichViewEdit;
frm: TForm;
sStyle: TRVStyle;
begin
try
Stream := TMemoryStream.Create;
frm := TForm.Create(nil);
sStyle := TRVStyle.Create(frm);
Dest := TDBRichViewEdit.Create(frm);
Dest.Parent := frm;
Dest.Style := sStyle;
Dest.DataField := 'INFODATA';
Dest.Datasource := dsTo;
Source := TDBrichViewEdit.Create(frm);
Source.Parent := frm;
Source.Style := sStyle;
Source.DataField := 'INFODATA';
Source.Datasource := dsFrom;
if (dsTo.DataSet.Bof and dsTo.DataSet.Eof) then
begin
dsTo.DataSet.Insert;
end else
begin
dsTo.DataSet.Edit;
end;
ItemNo := Dest.ItemCount -1;
Offset := Dest.GetOffsAfterItem(ItemNo);
Dest.SetSelectionBounds(ItemNo, Offset, ItemNo, Offset);
Source.SaveRTFToStream(Stream, False);
Stream.Position := 0;
Dest.InsertRTFFromStreamEd(Stream);
Dest.Format;
finally
FreeAndNil(Dest);
FreeAndNil(Source);
FreeAndNil(sStyle);
FreeAndNil(frm);
FreeAndNil(Stream);
cxPageControl1.ActivePage := DBRichView_Dest;
end;
end;
[/code]
Posted: Wed Sep 21, 2011 1:33 pm
by Sergey Tkachenko
From the first sight, the code looks correct. I need a sample project that I can compile to reproduce the problem.
Posted: Wed Sep 21, 2011 1:34 pm
by arnfinn
Hi!
Give me an email address and I will send it to you.
Thx.
Posted: Wed Sep 21, 2011 1:43 pm
by Sergey Tkachenko
richviewgmailcom
Posted: Wed Sep 21, 2011 1:52 pm
by arnfinn
you got m@il.
Arnfinn
Posted: Wed Sep 21, 2011 4:14 pm
by Sergey Tkachenko
Received. I'll check it tomorrow.
Posted: Thu Sep 22, 2011 5:57 pm
by Sergey Tkachenko
You insert RTF in Dest, but then you destroy Dest without posting to a database.
Instead of Dest.Format, call dsTo.DataSet.Post.