Page 1 of 1
Access Violation when I press CTRL+A on the header
Posted: Thu Oct 13, 2022 10:26 am
by Vitalii
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.
Re: Access Violation when I press CTRL+A on the header
Posted: Thu Oct 13, 2022 3:57 pm
by Sergey Tkachenko
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.
Re: Access Violation when I press CTRL+A on the header
Posted: Fri Oct 14, 2022 10:32 am
by Vitalii
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:
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;
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
Re: Access Violation when I press CTRL+A on the header
Posted: Fri Oct 14, 2022 11:35 am
by Sergey Tkachenko
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:
Code: Select all
if Shift = [ssCtrl] then
begin
SRichViewEdit1.ActiveEditor.SelectAll;
abort;
end;
2) Move the execution of this command outside of this event (using PostMessage)
3) Use an action (/ menu item / button) with Ctrl+A shortcut.
Re: Access Violation when I press CTRL+A on the header
Posted: Fri Oct 14, 2022 12:23 pm
by Vitalii
Ok, thanks for the clarification!