Page 1 of 1

Problem streaming to/from cells

Posted: Wed Jun 13, 2012 8:52 pm
by JonRobertson
I'm using the SaveCellToRVF and LoadRVFInCell procedures from the copyfromcell example at http://www.trichview.com/forums/viewtop ... =cell+save

However, I'm having a problem with it that I can't track down. I created a demo application that does the exact same thing as my main app, although without the overall architecture of the main app (like form inheritance and such). The demo app does not exhibit the problem.

Basically, I get a List Index Out of Bounds when SaveCellToRVF executes LoadRVFFromStream:

Code: Select all

  Cell.SaveRVFToStream(Result, False, clNone, nil, nil);
  Result.Position := 0;
  //!!! Index Out of Bounds occurs when next line is executed!!!
  rv.LoadRVFFromStream(Result);
I've narrowed it down to CRVFData.TCustomRVFormattedData.Item2DrawItem:

Code: Select all

  item := GetItem(ItemNo);     // ItemNo is zero here
  DrawItemNo := item.DrawItemNo;  // item.DrawItemNo is -1 here
  if item.StyleNo<0 then begin           // StyleNo = 0, so this is skipped
    DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs;
    exit;
  end;
  //!!! Exception occurs here, because DrawItemNo = -1!!!
  DrawItemOffs := ItemOffs-DrawItems[DrawItemNo].Offs+1;
Unfortunately, I'm not sure what else I can provide, since I haven't been able to reproduce in my test app.

Posted: Thu Jun 14, 2012 8:37 am
by Sergey Tkachenko
Please create a simple test project and send it to richviewgmailcom.

Posted: Thu Jun 14, 2012 11:16 am
by JonRobertson
Sergey Tkachenko wrote:Please create a simple test project and send it to richviewgmailcom.
As I said above, the issue does not repeat in my test app.

Is there anything else we can do? I can be available during your normal hours if we could do something "live", such as a remote connection or something.

Thanks for any help you can provide.

Posted: Thu Jun 14, 2012 2:38 pm
by Sergey Tkachenko
Compile your application with the following compiler options:
stack frames ON
optimization OFF.
Rebuild it completely.
When the exception happens, open the call stack window, copy it content (Ctrl+A, Ctrl+C) and post here or send by email.

Posted: Thu Jun 14, 2012 2:54 pm
by JonRobertson
My rveHidden is a TRichViewEdit dropped on the form, with Visible = False. I never use it until I load/save the cell's RVF to a stream.

I added a call to rveHidden.Format before loading/saving the cell's RVF, and the List Index Out of Bounds stopped.

Posted: Fri Jun 15, 2012 11:24 am
by Sergey Tkachenko
It's strange. SaveRVFToStream, LoadRVFFromStream, InsertRVFFromStream does not require formatting.
However, if you use InsertRVFFromStreamEd, formatting is necessary.

Posted: Fri Jun 15, 2012 1:06 pm
by JonRobertson
Sergey Tkachenko wrote:It's strange. SaveRVFToStream, LoadRVFFromStream, InsertRVFFromStream does not require formatting.
However, if you use InsertRVFFromStreamEd, formatting is necessary.
When it started failing, I tried various combinations. Since I'm working with RichViewEdits, I switched to InsertRVFromStreamEd, thinking using editor-style methods would be better with RichViewEdit. The variation that "started working" after I added Format was using InsertRVFromStreamEd. Not sure why the other variations weren't working, but that's OK. I'm happy now. :)

Since I'm working with RichViewEdit, I keep wanting to use InsertRVFromStreamEd with the cell (TCustomRVFormattedData). Oh well. ;)

Posted: Fri Jun 15, 2012 1:18 pm
by Sergey Tkachenko
It's ok, but slower.

Posted: Fri Jun 15, 2012 1:53 pm
by JonRobertson
Sergey Tkachenko wrote:It's ok, but slower.
Thanks for the heads-up on that. Performance is important to me. Right now I'm behind on a critical deadline. But down the line I'll spend more time trying to get it to work without InsertRVFFromStreamEd.

I'd like a better understanding of when viewer-style methods are safe to use and the best practices of when to use each. I've still got so much to learn about TRichView. Right now I'm playing it safe and trying not to use viewer-style methods with TRichViewEdit.

Posted: Fri Jun 15, 2012 2:28 pm
by Sergey Tkachenko
Editing methods need to be used when you want to implement an editing operation that must be undoable.
Non-editing operations should be used for loading and document generation, in the sequence:

Code: Select all

rve.Clear;
<non-editing operations>
rve.Format;

Re: Problem streaming to/from cells

Posted: Sun Mar 29, 2020 11:33 am
by Vitalii
I had a similar situation (DrawItemNo = -1). I solved the problem by adding Edit.Format right after SaveRVFToStream.

Re: Problem streaming to/from cells

Posted: Sun Mar 29, 2020 8:09 pm
by Sergey Tkachenko
The last message in this topic was posted 8 years ago...

Format is needed after operations that change the document, not after saving.