Enter Key and URL Detection

General TRichView support forum. Please post your questions here
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Enter Key and URL Detection

Post by jnap »

Hi,

I have a problem where trying to get auto URL detection working - the Enter Key is not being detected, this also happens with the Hypertext\URLS Demo

Only - Space, Tab, semicolon and comma is working but not the Enter Key...

I am using Delphi 2007 on Windows Vista Ultimate x64

Would you be able to look into this and see if there is a problem?

I use the code from the Demo:

Code: Select all

procedure TMain.rveKeyPress(Sender: TObject; var Key: Char);
begin
  if Key in [' ', #13, #9, ';', ','] then begin
    // url detection
      DetectURL(rve, URLScanEvent, True);
    // closing url if necessary
    TerminateHyperlink(rve, URLScanEvent, Key in [' ', #13, #9, ';', ',']);
  end;
end;
Many thanks

jnap
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use OnKeyDown instead
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Currently, the best solution is removing #13 from this event, and adding a new event:

Code: Select all

procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key=VK_RETURN) then begin
    rvActionsResource.rvActionInsertHyperlink1.DetectURL(RichViewEdit1);
    rvActionsResource.rvActionInsertHyperlink1.TerminateHyperlink(RichViewEdit1);
  end;    
end;
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

Hi,

may be a silly question - but what is rvActionsResource - I get undeclared on these lines...

What unit must be added for this?
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

Hi,

Found the unit: dmActions

The trouble is I get an Access Violation when pressing the Enter key using the code you suggest.
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

I think I have worked it out now, I just create it and free it when needed :)

Thanks for your help. I got there in the end :D

jnap
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can add this datamodule in your application. Make sure that it is autocreated, and created before any form that uses it.
jnap
Posts: 31
Joined: Sat Sep 30, 2006 6:23 pm

Post by jnap »

Hi,

Thanks for your help.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian »

I have the same problem with Enter key. Nothing helps!
My code worked for a long time but since some recent RVE version (I think v.14) my code from your samples stopped working.
Only Space and Tab works, Enter - does not. Using OnKeyDown event...
Here is my code:

Code: Select all

procedure TMainForm.RichViewEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if Key in [VK_SPACE,VK_RETURN,VK_TAB] then begin
    DetectURL(RichViewEdit1);
    TerminateHyperlink(RichViewEdit1);
    if LiveCorrect then AutoCorrect(RichViewEdit1, RVAddictSpell31);
  end;
end;

procedure TMainForm.TerminateHyperlink(rve:TCustomRichViewEdit);
begin
  if (rve.CurTextStyleNo=rve.CurItemStyle)
    and rve.Style.TextStyles[rve.CurTextStyleNo].Jump
      and not rve.SelectionExists then begin
        rve:=rve.TopLevelEditor;
        if rve.OffsetInCurItem>=rve.GetOffsAfterItem(rve.CurItemNo) then
          rve.CurTextStyleNo:=GetNonHypertextStyleNo(rve.CurTextStyleNo);
  end;
end;
Delphi XE4 (same problem was on XE3)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please send a sample project to richviewgmailcom.
I cannot reproduce this problem in the ActionTest demo.
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian »

The problem is I don't use rvActions for this and my project is huge. Anyway I'll try to reproduce it in a new project.

The problem is it worked fine for a long time and I didn't change anything there. But from some new RVE version it doesn't works for VK_RETURN.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I cannot help if I cannot reproduce the problem.

There is not enough information.
TerminateHyperlink is not called?
Called, but rve.CurTextStyleNo<>rve.CurItemStyle?
GetNonHypertextStyleNo returns unexpected results?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

By the way, did you enable StyleTemplates?
Martian
Posts: 95
Joined: Sun Apr 03, 2011 7:32 pm

Post by Martian »

Didn't touch StyleTemplates and I don't need them.
Where should I check this option? In RVStyle or RVE?

And TerminateHyperlink calls.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

TRichView.UseStyleTemplates.

TRichViewEdit processes Enters differently if style templates are used).
However, it should not be the reason, because the event occurs before the default processing of Enter.
Post Reply