Page 1 of 1
Having issue with LoadRVFFromStream
Posted: Thu Jun 21, 2012 6:54 pm
by Vandy1Fan
I am saving RVF data to a sql database in hex. I read it from the database and convert the hex to a string.
I read the string to a stream.
I call LoadRVFFromStream. The RichViewEdit is blank.
I have tried this with both a TStringStream and a TMemoryStream.
Here is the code.
procedure TfrmMain.FormShow(Sender: TObject);
var
vStream:TStringStream;
vStr:string;
begin
RichViewEdit1.Clear;
try
vStream:=TStringStream.Create;
vStr:=HexToString(adoquery1.FieldByName('RTFData').asstring);
vStream.WriteString(vStr);
vStream.Position:=0;
if not RichViewEdit1.LoadRVFFromStream(vStream) then
ShowMessage('Unable to load from stream');
finally
Freeandnil(vStream);
end;
end;
Here is how I'm loading the rvf to the database
Posted: Thu Jun 21, 2012 7:11 pm
by Vandy1Fan
procedure TfrmMain.actSaveExecute(Sender: TObject);
var
vStream:TStringStream;
xStream:TMemoryStream;
vStr:string;
vSL:TStringList;
begin
try
vSL:=TStringList.Create;
vStream:=TStringStream.Create;
xStream:=TMemoryStream.Create;
RichViewEdit1.SaveRVFToStream(xStream, false);
xStream.Position:=0;
vStream.LoadFromStream(xStream);
vStr:=vStream.ReadString(vStream.Size);
with ADOQuery1 do
begin
if active then
active:=false;
with SQL do
begin
Clear;
Add('select RTFData from TestRTF');
end;
Open;
Edit;
FieldByName('RTFData').AsString:=StringToHex(vStr);
Post;
Close;
end;
finally
Freeandnil(vSL);
Freeandnil(vStream);
Freeandnil(xStream);
end;
end;
Posted: Fri Jun 22, 2012 9:18 am
by Sergey Tkachenko
Please save the value in vStr (before calling LoadRVFFromStream) to a file and send this file to me (richviewgmailcom)
File sent
Posted: Fri Jun 22, 2012 2:10 pm
by Vandy1Fan
I have emailed you the file.
I found a way around it by using the DBRichViewEdit.
I will be officially registering later today.
Posted: Sun Jun 24, 2012 8:35 am
by Sergey Tkachenko
Answered by email
Here is what I did
Posted: Tue Jun 26, 2012 5:16 pm
by Vandy1Fan
I took your example program ActionTestRibbon.
I created a SQLServer table called TestRTF with 1 field called RTFData. RTFData is a varchar(MAX).
I created a new TAction in the Action Manager.
Here is the onExecute for the action.
Code: Select all
procedure TfrmMain.actSaveExecute(Sender: TObject);
var
vStream:TStringStream;
xStream:TMemoryStream;
vStr:string;
vSL:TStringList;
begin
try
vSL:=TStringList.Create;
vStream:=TStringStream.Create;
xStream:=TMemoryStream.Create;
RichViewEdit1.SaveRVFToStream(xStream, false);
xStream.Position:=0;
vStream.LoadFromStream(xStream);
vStr:=vStream.ReadString(vStream.Size);
with ADOQuery1 do
begin
if active then
active:=false;
with SQL do
begin
Clear;
Add('select RTFData from TestRTF');
end;
Open;
Edit;
FieldByName('RTFData').AsString:=StringToHex(vStr);
Post;
Close;
end;
finally
Freeandnil(vSL);
Freeandnil(vStream);
Freeandnil(xStream);
end;
end;
This saves the data to the database in hex. This must be done because of the /0 (ascii 0) characters that are in the data.
After saving I exit the program. When I restart the program, I reload the data from the database.
Code: Select all
procedure TfrmMain.FormShow(Sender: TObject);
var
vStream:TStringStream;
xStream:TMemoryStream;
vTemp:TextFile;
Inserted:boolean;
vStr:string;
vSL:TStringList;
begin
Inserted:=false;
with AdoQuery1 do
begin
if active then
active:=false;
with SQL do
begin
Clear;
Add('select RTFData from TestRTF');
end;
Open;
try
vSL:=TStringList.Create;
vStream:=TStringStream.Create;
RichViewEdit1.Clear;
xStream:=TMemoryStream.Create;
xStream.Position:=0;
vStr:=HexToString(FieldByName('RTFData').asstring);
AssignFile(vTemp, 'temprvf.rvf');
Rewrite(vTemp);
writeln(vTemp, vStr);
Flush(vTemp);
CloseFile(vTemp);
// tried this as a work-around
rvActionOpen1.LoadFile(RichViewEdit1, 'temprvf.rvf', ffiRVF);
// this did not work
vStream.WriteString(vStr);
vStream.SaveToStream(xStream);
xStream.WriteBuffer(Pointer(vStr)^, Length(vStr));
vStream.WriteString(vStr);
vStream.Position:=0;
TRVYesNoAuto.rvynaAuto
RichViewEdit1.LoadFromStream(vStream,rvynaAuto);
if not RichViewEdit1.LoadRVFFromStream(vStream) then
ShowMessage('Unable to load from stream');
finally
Freeandnil(vStream);
Freeandnil(xStream);
Freeandnil(vSL);
end;
end;
end;
end;
Posted: Mon Jul 02, 2012 12:45 pm
by Sergey Tkachenko
In your example, the problem is in incorrect RVF record for an image.
It does not look like a document corruption, it looks like this picture was saved wrong.
So the problem may manifest itself only on specific data. In order to find the reason of this problem, I need to know how this picture was added to the document, and which properties of this picture item were assigned and how.
Posted: Mon Jul 02, 2012 1:23 pm
by Vandy1Fan
I'm using the TDBRichViewEdit and having no issues.