Hi, I am getting Access Violation when I press CTRL+A on the header (TSRichViewEdit). Debugger shows that the property RVData=nil in the methods TCustomRichViewEdit.KeyDown and TCustomRichView.KeyDown. I set a temporary check at the beginning of the method:
if RVData = nil then Exit;
But perhaps a better solution is needed.
Access Violation when I press CTRL+A on the header
-
- Site Admin
- Posts: 17602
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Access Violation when I press CTRL+A on the header
I need a test project reproducing this problem.
I tried in a simple ScaleRichView demo - Ctrl+A does nothing, as it should.
I tried in ActionTest demo - Ctrl+A selects the header content (it is done by TrvActionSelect all that has Ctrl+A shortcut).
So, I cannot reproduce this problem. And I do not understand how RVData can be nil: RichViewEdit.RVData is created in the constructor and destroyed in the destructor.
I need to know how exactly Ctrl+A is processed in your project, and a simple test project would be useful.
Please send it to email richviewgmailcom.
I tried in a simple ScaleRichView demo - Ctrl+A does nothing, as it should.
I tried in ActionTest demo - Ctrl+A selects the header content (it is done by TrvActionSelect all that has Ctrl+A shortcut).
So, I cannot reproduce this problem. And I do not understand how RVData can be nil: RichViewEdit.RVData is created in the constructor and destroyed in the destructor.
I need to know how exactly Ctrl+A is processed in your project, and a simple test project would be useful.
Please send it to email richviewgmailcom.
Re: Access Violation when I press CTRL+A on the header
OK, I have already sent a letter with an example. It seems that this bug appears only if there is a table in the Header. I'm assuming that the table has a dynamic editor and catches the appropriate events, and that's where RVData=nil can be.
To reproduce issue:
1. Set event handler for SRichViewEdit:
2. Open the header for editing.
3. Insert table into header
4. Set cursor to the cell (activate focus on table)
5. Press CTRL+A --> Access Violation here
To reproduce issue:
1. Set event handler for SRichViewEdit:
Code: Select all
procedure TForm1.SRichViewEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
65: // Ctrl+A = Select All
if Shift = [ssCtrl] then
SRichViewEdit1.ActiveEditor.SelectAll;
end;
end;
3. Insert table into header
4. Set cursor to the cell (activate focus on table)
5. Press CTRL+A --> Access Violation here
-
- Site Admin
- Posts: 17602
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Access Violation when I press CTRL+A on the header
There is a problem in calling SelectAll from OnKeyDown.
When the caret is in an inplace editor of a table cell, this event is called from this inplace editor. You cannot call methods that destroy this table inplace editor from inside of OnKeyDown event, because VCL code processing key down will access to this editor later. The problem is not only in TRichView code, but in code of VCL library too.
The methods that destroy an inplace editor: (1) clearing document (2) moving the caret outside of this editor (including SelectAll)).
Solutions:
1) A quick and dirty solution: raise a silent exception after SelectAll:
2) Move the execution of this command outside of this event (using PostMessage)
3) Use an action (/ menu item / button) with Ctrl+A shortcut.
When the caret is in an inplace editor of a table cell, this event is called from this inplace editor. You cannot call methods that destroy this table inplace editor from inside of OnKeyDown event, because VCL code processing key down will access to this editor later. The problem is not only in TRichView code, but in code of VCL library too.
The methods that destroy an inplace editor: (1) clearing document (2) moving the caret outside of this editor (including SelectAll)).
Solutions:
1) A quick and dirty solution: raise a silent exception after SelectAll:
Code: Select all
if Shift = [ssCtrl] then
begin
SRichViewEdit1.ActiveEditor.SelectAll;
abort;
end;
3) Use an action (/ menu item / button) with Ctrl+A shortcut.
Re: Access Violation when I press CTRL+A on the header
Ok, thanks for the clarification!