Access Violation when I press CTRL+A on the header

General TRichView support forum. Please post your questions here
Post Reply
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

Access Violation when I press CTRL+A on the header

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

Re: Access Violation when I press CTRL+A on the header

Post 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.
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

Re: Access Violation when I press CTRL+A on the header

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

Re: Access Violation when I press CTRL+A on the header

Post 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.
Vitalii
Posts: 61
Joined: Sat Oct 20, 2018 2:55 pm

Re: Access Violation when I press CTRL+A on the header

Post by Vitalii »

Ok, thanks for the clarification!
Post Reply