how to assign RV+images correctly?
Posted: Fri Oct 17, 2008 9:02 pm
Got an interesting bug. Adding Text+Graphics to one richview instance, then saving to the stream and load to the second instance. when clearing the first one, got the AV on the second (!) image item inside TCustomRVData.InternalFreeItem (when trying to call Image.Free (TRVGraphicItemInfo.Destroy), the Destroy goes to a nil). As a result I get exception, the graphic isn't destroyed and can't free first instance of richview...
What is more interesting is that error appears only if I use AddPictureEx... When adding text and replacing with InsertPicture - everything works fine...
to be more specific I'll illustrate it with that code:
but this code works without bugs:
the second example works without bug, but much more slower, than the first one. Any thoughts about the reason of that strange appearance? I thought that maybe thats rvoTagsArePChars caused this, but no, nothing like it
What is more interesting is that error appears only if I use AddPictureEx... When adding text and replacing with InsertPicture - everything works fine...
to be more specific I'll illustrate it with that code:
Code: Select all
First.Clear;
First.Format;
for I := 0 to 99 do//the cycle is absurde, but this is only a demostration
if I mod 2 = 0 then
First.AddTextNLW(CRLF + 'text', 0, -1, 1, True)
else
begin
FindPicture(I, gr);//gr: TGraphic
if gr <> nil then
begin
gr1 := RV_CreateGraphics(TGraphicClass(gr.ClassType));
gr1.Assign(gr);
First.AddPictureEx('img', gr, -1, rvvaMiddle);
end;
end;
First.FormatTail;
mem := TMemoryStream.Create;
First.SaveRVFToStream(mem, False);
mem.Position := 0;
First.Clear; //<----- Fails here
First.Format;
Second.AppendRVFFromStream(mem, -1);
FreeAndNil(mem);
Code: Select all
First.Clear;
First.Format;
for I := 0 to 99 do
begin
First.AddTextNLW(CRLF + 'text', 0, -1, 1, True);
First.AddTextNLW('img' + IntToStr(I), 0, -1, 1, True);
end;
for I := 0 to 99 do
begin
FindPicture(I, gr);
while First.SearchTextW('img' + IntToStr(I), []) do
begin
gr1 := RV_CreateGraphics(TGraphicClass(gr.ClassType));
gr1.Assign(gr);
First.InsertPicture('img' + IntToStr(I), gr1, rvvaAbsMiddle);
end;
end;
First.FormatTail;
mem := TMemoryStream.Create;
First.SaveRVFToStream(mem, False);
mem.Position := 0;
First.Clear;
First.Format;
Second.AppendRVFFromStream(mem, -1);
FreeAndNil(mem);