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

General TRichView support forum. Please post your questions here
Post Reply
Guest

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

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

Post 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?
Guest

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

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

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

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

Post 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]
?
Guest

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

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

Post 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!
Guest

Post by Guest »

The new version solved my problem! Thank you very much!
Post Reply