access violation on table.cell[x,y].edit twice
access violation on table.cell[x,y].edit twice
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?
// 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?
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
No, it's not necessary.
I added the following code in the ActionTest demo:
and it works fine.
How do you call that code?
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;
How do you call that code?
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.
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.
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;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
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.
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;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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):
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!
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;
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!
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Yes, I'm using TRichView 1.9.8 and Delphi 2005. I've send an email to [email protected] to request the new version.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.
Thank you very much for your help!