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;
Having issue with LoadRVFFromStream
Here is how I'm loading the rvf to the database
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;
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;
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Here is what I did
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.
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.
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;
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;
-
- Site Admin
- Posts: 17564
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.