Page 1 of 1

access violation on table.cell[x,y].edit twice

Posted: Tue Sep 27, 2005 1:43 pm
by Guest
The following results in an access violation (somewhere in the destruction of the inline editor).

// Everything is fine
lTable.Cells[0,0].Edit;
// Now the access violation occurs
lTable.Cells[0,1].Edit;


Do I have to get the cell out of edit mode first, if so, how?

Posted: Tue Sep 27, 2005 2:34 pm
by Sergey Tkachenko
No, it's not necessary.

I added the following code in the ActionTest demo:

Code: Select all

procedure TForm3.Button2Click(Sender: TObject);
var table: TRVTableItemInfo;
    rve: TCustomRichViewEdit;
begin
  if RichViewEdit1.GetCurrentItemEx(TRVTableItemInfo, rve,
    TCustomRVItemInfo(table)) then begin
    table.EditCell(0, 0);
    if (table.Rows[0].Count>1) and (table.Cells[0, 1]<>nil) then
      table.EditCell(0, 1);
  end;
end;
and it works fine.

How do you call that code?

Posted: Tue Sep 27, 2005 2:40 pm
by Guest
I have a form with a richvieweditor on it.

I have another form, with a button on it. When I press that button, the form with the richvieweditor on it is created (but not shown!).

Programmatically I open a document which contains one table, and then look for the table object in the richvieweditor component.

There, insert a new row (again, programmatically), and then "edit" the first cell, and then the second cell.

That's it in a nutshell.

Posted: Tue Sep 27, 2005 2:45 pm
by Guest
This is (part of) the code in which it goes wrong:

Code: Select all

            // Add a new row
            rvEditor.BeginItemModify(lTable.GetMyItemNo, lModifyData);
            lTable.InsertRows(lCount + 2, 1, lCount + 1 );
            rvEditor.EndItemModify(lTable.GetMyItemNo, lModifydata);
            rvEditor.Change;
            rvEditor.Reformat;

            // Copy fields from current row to new row
            lBackground := TRVBackground.Create(false);
            for lColumnCount := 0 to lRow.Count - 1 do
            begin
              rvEditor.BeginItemModify(lTable.GetMyItemNo, lModifyData);

              lTable.EditCell(lCount + 2, lColumnCount);
              lTable.Cells[lCount + 1, lColumnCount].GetRVData.Edit;
              lTable.Cells[lCount + 1, lColumnCount].SelectAll;
              lTable.Cells[lCount + 1, lColumnCount].CopyRVF ( clHighlightText
                                                                 , lBackground
                                                                 );
              rvEditor.Paste;

              rvEditor.EndItemModify(lTable.GetMyItemNo, lModifydata);
              rvEditor.Change;
              rvEditor.Reformat;
            end;
            lBackground.Destroy;

Posted: Tue Sep 27, 2005 3:45 pm
by Sergey Tkachenko
Do you want to add a new row and copy content of the last row to it?

Some notes:
1) Reformat is not needed, BeginItemModify-EndItemModify does this work,
2) Table.EditCell(r,c) and Cell[r,c].Edit are equivalent methods.
3) SelectAll and CopyRVF must be called for Cell.GetRVData.
4) The second pair of BeginItemModify-EndItemModify is not required, because Paste reformats document itself.

But all of the issues above are not critical, they will not cause AV.
More important issues:
5) What's the value of lCount? If it > lTable.Rows.Count-2, there will be an error.
6) Does your table have merged cells? You should check if cell <> nil.

Posted: Wed Sep 28, 2005 6:57 am
by Guest
First of all, thanks a lot for your help, and your fast response.

I made a new codesample, which is much simpler, but still causes the access violation. I'm using it with a simple RTV document, which contains only one table, with 2 columns and 2 rows. Each cell has some text in it.

Code: Select all

  // Find the table
  for lCount := 0 to rvEditor.ItemCount - 1 do
    if ( rvEditor.GetItemStyle(lCount) = rvsTable ) then
    begin
      // Cast it
      lTable := TRVTableItemInfo(rvEditor.GetItem(lCount));

      // Edit two cells (AV on the 2nd edit)
      lTable.Cells[0,0].Edit;
      lTable.Cells[0,1].Edit;
    end;

Posted: Wed Sep 28, 2005 7:30 am
by Sergey Tkachenko
I tried, this code executes without errors when added in the ActionTest demo.
Are you sure that
1) You do not have any code in events which may cause AV
2) All tables have more than 1 column
3) In all tables the cell [0, 1] is not merged with the cell [0, 0]
?

Posted: Wed Sep 28, 2005 8:59 am
by Guest
I created a new form, just to be sure. All I have put on it are a TRichViewEdit component, and a TRVStyle component (which is linked to the TRichViewEdit component). I allowed the richviewedit component to dynamically add styles.

From the main form, I do the following (TCPDocumentObject is just an object with a datastream):

Code: Select all

var
  Form1 : TForm1;
  lDocument : TCPDocumentObject;
begin
  Form1 := TForm1.Create(nil);

  // Create the document
  lDocument := TCPDocumentObject.Create(C_DOCTYP_RTV);
  lDocument.ReadOnly := False;
  lDocument.DocType := C_DOCTYP_RTV;
  lDocument.DataStream.Clear;

  // Load file
  if ( FileExists('test.rtv') ) then
  begin
    Form1.rvEditor.Clear;
    lDocument.DataStream.LoadFromFile('test.rtv');
    lDocument.DataStream.Seek( 0, soFromBeginning );
    Form1.rvEditor.SetFReadOnly(False);
    Form1.rvEditor.LoadRVFFromStream(lDocument.DataStream);
    Form1.rvEditor.Change;
    Form1.rvEditor.Format;
    Form1.rvEditor.Modified := False;
  end;

  // Show the editor
  Form1.ShowModal;

  Form1.Destroy;
end;
The editor opens up, with my document loaded. That document contains the table with 2 rows and 2 columns (no merged cells or anything).

When I click in a cell (with the mouse) for the first time, everything works. After that, if I click in a different cell, and access violation is raised.

Hope this clarifies it a bit.

Thanks again!

Posted: Wed Sep 28, 2005 9:16 am
by Sergey Tkachenko
You use TRichView 1.9.8 and Delphi 2005, aren't you?
TRichView 1.9.8 has a bug appearing in D2005.

If yes,
- if you are a registered user, please update to the newer version;
- if not, I can send updated version to you by e-mail.

Posted: Wed Sep 28, 2005 9:51 am
by Guest
Sergey Tkachenko wrote:You use TRichView 1.9.8 and Delphi 2005, aren't you?
TRichView 1.9.8 has a bug appearing in D2005.

If yes,
- if you are a registered user, please update to the newer version;
- if not, I can send updated version to you by e-mail.
Yes, I'm using TRichView 1.9.8 and Delphi 2005. I've send an email to [email protected] to request the new version.

Thank you very much for your help!

Posted: Wed Sep 28, 2005 9:58 am
by Guest
The new version solved my problem! Thank you very much!