Problem streaming to/from cells

General TRichView support forum. Please post your questions here
Post Reply
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Problem streaming to/from cells

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please create a simple test project and send it to richviewgmailcom.
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's strange. SaveRVFToStream, LoadRVFFromStream, InsertRVFFromStream does not require formatting.
However, if you use InsertRVFFromStreamEd, formatting is necessary.
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Post 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. ;)
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It's ok, but slower.
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

Re: Problem streaming to/from cells

Post by Vitalii »

I had a similar situation (DrawItemNo = -1). I solved the problem by adding Edit.Format right after SaveRVFToStream.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Problem streaming to/from cells

Post 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.
Post Reply