T O P I C R E V I E W |
jrpcguru |
Posted - Dec 08 2023 : 18:00:42 I am confused by InsertLink. The demo program seems to do nothing that simply pasting in a URL doesn't do.
Your sample code from the help file:
Editor.InsertLink( 'http://www.ImageEn.com', 'ImageEn Web Site' );
This works to insert the URL with a nice title that visually replaces the actual URL. And it works in my program when I immediately click on the new URL. But, if I save and close the file, when I reopen the file, it is mostly dead. Clicking or double clicking the URL no longer functions. A couple of times it has worked correctly, but mostly failed. I just tested it in the demo program and it didn't even work correctly when initially entered into your demo document, and didn't work when reloading either.
I opened the saved RTF file in MS Word 2019 and it correctly launched the URL. That suggests the URL/title combination is properly formed, but TIERichEdit is having trouble activating it?
My preferred usage would be to have the user select the URL in the RTF field, then prompt for the title. When I do that, it would be nice to be able to determine if the selected text was, in fact, a URL. TIERichEdit clearly has an internal method for identifying URLs. Is it possible to have a function, perhaps named IsURL()?
BTW: I don't know when you added documentation for rich text tables. I discovered it while trying out InsertLink. Apparently rich text tables are more primitive than MS Word, but I was able to add a very nice and functional feature to my RTF editor. Thank you!
J.R. |
11 L A T E S T R E P L I E S (Newest First) |
xequte |
Posted - Dec 15 2023 : 18:58:16 Hi JR
The RichEdit API recognizes URLs (though does not check whether they are valid), but it does not surface that functionality. You should just write your own method for that, or use one of the many examples on the internet.
Nigel Xequte Software www.imageen.com
|
jrpcguru |
Posted - Dec 14 2023 : 18:35:17 Thank you for the quick reply. I'm glad to hear a solution was found for the odd non-activation of URLs.
I don't really understand the Stack Overflow links you provided. It seems obvious that TIERichEdit has this functionality built in since it quickly identifies URLs to make them blue and underline. Is there any way to expose that functionality? I certainly don't want to test URLs by launching them on the internet since the user's computer might not be connected to the internet when needed. Or, can you publish the code used internally by TIERichEdit?
J.R. |
xequte |
Posted - Dec 14 2023 : 16:55:47 Hi JR
Please email me for an update that gets around some weirdness in the way RichEdit API handles the links when saving/loading.
Regarding checking whether the text is a URL, try something like:
https://stackoverflow.com/questions/68665833/check-whether-a-string-is-a-valid-url-in-delphi
Nigel Xequte Software www.imageen.com
|
jrpcguru |
Posted - Dec 14 2023 : 16:15:31 I think we are getting closer to the problem, now that we've clarified the need for EditorURLClick in the demo program. I added the this code to the demo program.
procedure TMainForm.EditorURLClick(Sender: TObject; const URL: string;
Button: TMouseButton);
begin
showmessage(URL);
ShellExecute(Handle, nil, PChar(URL), nil, nil, SW_SHOWNORMAL)
end;
And I modifed the btnInsertLink to this code:
procedure TMainForm.btnInsertLinkClick(Sender: TObject);
//need to select the URL so it can be translated into an English title
var
surl, sURLTitle: string;
begin
sURL := editor.SelText;
sURL := trim(sURL);
sURLTitle := InputBox( 'Specify URL Name', 'Specify URL Name' + ':', sURLTitle );
if surl <> '' then
Editor.InsertLink( surl, sURLTitle );
end;
If I paste in a URL and then select it, the btnInsertLinkClick lets me type in an English title for that URL. And it successfully inserts the URL and the English title, as expected.
Adding the showmessage(URL) to EditorURLClick finally may have found the actual problem.
If I insert a single URL and then click on it, it successfully launches the URL. If I save the file, then reload, clicking on the URL does not work. The Showmessage is never activated.
If I insert multiple URLs in a new file, each works until I save and reload. Then the last URL does not activate. The Showmessage is never activated.
I modified the code in my program to agree with this and found similar results. One exception: I started with a single URL, save, reload, then worked up to a total of 5 URLs. At one point the bottom 2 URLs failed to execute when the file was reloaded. The last one always failed to execute. I use the Trim(sURL) to hopefully remove accidental excess text. Without this line, I deliberately selected the URL with an empty line before and an empty line after and that caused the URL to fail even if it was not the last URL in the file. Clearly it needs to be a valid URL only.
I'm still wondering if there is a way to confirm that the selected text is actually a valid URL before the InputBox() asks for the English title?
J.R. |
xequte |
Posted - Dec 14 2023 : 14:19:17 Sorry, I didn't realise that you meant only that there was no click effect. Yes, you do need to assign a URLClick event for clicking to have an action.
Nigel Xequte Software www.imageen.com
|
jrpcguru |
Posted - Dec 12 2023 : 09:35:33 I do not use the TIERichEdit Import/Export feature at all in my program. I turned it off in the demo. Both programs fail to launch the link.
Word successfully launches the link when it is created by either Delphi program.
My program routinely launches links that I paste into a document. In fact, I have another program written in Delphi XE that also routinely launches links that are pasted in.
I just created a file with 2 pasted in URLs with the demo, saved it, and loaded into Word 2019. Word failed to turn the URLs blue, but otherwise launched them. The demo did not launch either URL, but it recognized them as URLs and turned them blue.
J.R.
I just noticed that my program uses different code for EditorURLClick than is shown in the help file.
procedure TMainForm.EditorURLClick(Sender: TObject; const URLText: string;
Button: TMouseButton);
var
URL: string;
begin
URL := URLText;
URL := StringReplace(URL, '"', '%22', [rfReplaceAll]);
ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL);
// ShellExecute(Handle, nil, PChar(URL), nil, nil, SW_SHOWNORMAL)
end;
The demo program does not use URLClick at all. If I use the code that is commented out, from the help file, it does not launch the URL but instead shrinks an open instance of File Explorer. I don't know where I got this version of code, but I use it in both of my programs, successfully. |
xequte |
Posted - Dec 11 2023 : 22:18:55 Hi JR
Perhaps something on your system is blocking the launching of web sites, or the handler for HTTP links is not adequately set.
Are you importing/exporting to Word when you get the error above?
Nigel Xequte Software www.imageen.com
|
jrpcguru |
Posted - Dec 11 2023 : 09:57:12 The test file also fails to launch the link.
I added your proposed code and it created a link: Memo1 = HYPERLINK "http://www.ImageEn.com" ImageEn Web Site Rich Text = {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\colortbl ;\red0\green0\blue255;} {\*\generator Riched20 10.0.22000}\viewkind4\uc1 \pard {\f0\fs20{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com" }}{\fldrslt{\ul\cf1 ImageEn Web Site}}}}\f0\fs20\par }
So, now we have matched ", but it still doesn't work.
I remembered that when I launch the demo, it always take a long time and creates this error message from Word:
I thought that might be the problem, even though I don't use this feature, yet, in my program. Unfortunately, turning this off had no effect on the link. I do wonder what is needed to actually allow TIERichEdit to import/export from Word?
J.R. |
xequte |
Posted - Dec 10 2023 : 18:54:00 Hi JR
Those are the versions I would expect, so I'm not sure why you are seeing something different than we get here.
How about if you use:
IERichEdit1.SelRTFText := '{\rtf1 {{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com" }}{\fldrslt{ImageEn Web Site}}}}';
Here is my test file:
attach/xequte/20231210185544_link.RTF 887 Bytes
Nigel Xequte Software www.imageen.com
|
jrpcguru |
Posted - Dec 10 2023 : 18:05:18 TIERichEdit.version = 8
Win 11
I just tried again with the same result. In addition to adding an InsertLink to previously existing RTF file, I tried making an entirely new file. Same problem. I modified your demo Insert Link button to insert: Editor.InsertLink( 'http://www.ImageEn.com', 'ImageEn Web Site' );
It doesn't work when entered into a new document.
memo1: HYPERLINK http://www.ImageEn.com ImageEn Web Site
Rich Text: {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\colortbl ;\red0\green0\blue255;} {\*\generator Riched20 10.0.22000}\viewkind4\uc1 \pard {\f0\fs20{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com }}{\fldrslt{\ul\cf1 ImageEn Web Site}}}}\f0\fs20\par }
I opened the file that was created by my program, using the demo, and then added another link to it:
memo1: HYPERLINK "http://www.ImageEn.com ImageEn Web Site
HYPERLINK http://www.ImageEn.com ImageEn Web Site
Rich Text: {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Arial;}} {\colortbl ;\red0\green0\blue0;\red0\green0\blue255;} {\*\generator Riched20 10.0.22000}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1 \pard {\cf1\fs28{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com "}}{\fldrslt{\ul\cf2\cf2\ul ImageEn Web Site}}}}\f0\fs28\par \par {{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com }}{\fldrslt{\ul\cf2 ImageEn Web Site}}}}\f0\fs28\par }
Neither of these links works. The first one, created by my program, includes a stray " before the http. Don't know if that means anything. If I use the demo to create a new file and insert the link,
memo1: HYPERLINK http://www.ImageEn.com ImageEn Web Site
Rich Text: {\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033\deflangfe1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {\colortbl ;\red0\green0\blue255;} {\*\generator Riched20 10.0.22000}{\*\mmathPr\mdispDef1\mwrapIndent1440 }\viewkind4\uc1 \pard {\f0\fs20{\field{\*\fldinst{HYPERLINK "http://www.ImageEn.com }}{\fldrslt{\ul\cf1 ImageEn Web Site}}}}\f0\fs20\par }
But it still doesn't work. Maybe the problem is the lack of closing "?
J.R. |
xequte |
Posted - Dec 10 2023 : 17:33:53 Hi JR
I'm not seeing that, at all. If I add a button to the RTF demo that has this code:
Editor.InsertLink( 'http://www.ImageEn.com', 'ImageEn Web Site' );
1. It correctly inserts a link into the editor that I can click to bring up imageen.com in my browser.
2. If I save it to an RTF file I can open that file in Microsoft Word and the link works as expected
3. If I load the file back into the RTF demo then the link also works as expected
What version of Windows are you using?
What does TIERichEdit.RichEditVersion return?
Nigel Xequte Software www.imageen.com
|
|
|