Page 1 of 2
Enter Key and URL Detection
Posted: Thu Oct 08, 2009 2:45 am
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
Posted: Thu Oct 08, 2009 10:58 am
by Sergey Tkachenko
Use OnKeyDown instead
Posted: Thu Oct 08, 2009 4:10 pm
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;
Posted: Thu Oct 08, 2009 7:56 pm
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?
Posted: Fri Oct 09, 2009 8:09 am
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.
Posted: Fri Oct 09, 2009 8:27 am
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
jnap
Posted: Fri Oct 09, 2009 2:10 pm
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.
Posted: Sat Oct 10, 2009 1:48 am
by jnap
Hi,
Thanks for your help.
Posted: Wed May 29, 2013 8:54 am
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)
Posted: Wed May 29, 2013 9:21 am
by Sergey Tkachenko
Please send a sample project to richviewgmailcom.
I cannot reproduce this problem in the ActionTest demo.
Posted: Wed May 29, 2013 7:19 pm
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.
Posted: Thu May 30, 2013 2:18 pm
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?
Posted: Thu May 30, 2013 2:19 pm
by Sergey Tkachenko
By the way, did you enable StyleTemplates?
Posted: Thu May 30, 2013 8:14 pm
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.
Posted: Fri May 31, 2013 12:42 pm
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.