URL link in TRichView

General TRichView support forum. Please post your questions here
Post Reply
jamiemi
Posts: 21
Joined: Sun Oct 30, 2005 3:33 pm

URL link in TRichView

Post by jamiemi »

I really love this component, but it has a really steep learning curve.

I have a data table with a binary field that holds Rich View data, saved from a TRichViewEdit. I can save off the data and retrieve it and all is good. If I create a URL link in the document, and try it, it links correctly. I can save it to DB, and when I retrieve it in the TRichViewEdit, it still links correctly. So far, so good. Note the editor is based in great detail on the ActionTest demo.

Now, here is the problem. If I create a link in a document and save it to the database, I also allow the user to pull that field into a TRichView for viewing only. When a field with a link is pulled into my TRichView, the link still looks like a link (blue with an underline.) However, it does not act like a link. I cannot automatically start up my browser, or go to the URL page by clicking, Ctrl-Clicking, or any other way. It looks like the 'link' itself is not really there, just the text with the underline.

When I first started testing this, reading the field into the TRichEdit caused a GPF. That problem was caused by rvoTagsArePChars being set to FALSE. That problem I figured out by scouring the help file. Setting that option value to TRUE solved the GPF problem. However, I cannot find any reference for this particular problem.

I did try to handle the events (OnReadHyperlink, OnWriteHyperlink) but neither one ever fires. I placed break points in each method, but they never were reached.

I am reasonably sure there is something simple that I am missing; any help would be appreciated!

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

Post by Sergey Tkachenko »

Do you use a hypertext cursor over this link in TRichView?

It should be enough to process OnJump event (OnReadHyperlink and OnWriteHyperlink are for RTF (Rich Text Format), hyperlinks are read from RVF (RichView Format) automatically).

Can you save this document to file and send it to me?
jamiemi
Posts: 21
Joined: Sun Oct 30, 2005 3:33 pm

More information

Post by jamiemi »

I traced through the example code and found the OnJump event. Again, borrowing liberally from the ActionText demo, I was able to write my own handler and it kind of works now.

First of all, here is the code:

procedure TfrmMain.rvMessJump(Sender: TObject; id: Integer);
var URL: String;
RVData: TCustomRVFormattedData;
ItemNo: Integer;
begin
TRichView(Sender).GetJumpPointLocation(id, RVData, ItemNo);
URL := PChar(TRichView(Sender).GetItemTag(ItemNo));
If (ShellExecute(Application.Handle, 'open', PChar(URL), nil, nil, SW_NORMAL) <= 32) Then
WriteStatus(SB, 'Was not able to open URL', TRUE);
end;

This works in most cases. However, there is one more problem with it. If the link is in a table, it does not work in the TRichView using this code, but the exact same link in the TRichViewEdit works correctly. When I try it from in the TRichView, the Jump is called, but the URL variable (in the above code) is loaded with '' (a NULL value.) Interestingly enough, if there is a link in the document in front of the table, the link in the table is not picked up, but the earlier link is. Again, the link in the table works correctly when I am using the TRichViewEdit and the same data field.

One more question for now. In the ReadHyperlink method, the example shows us to allocate a string from the heap as follows:

procedure TfrmMain.rvMessReadHyperlink(Sender: TCustomRichView;
const Target, Extras: String; DocFormat: TRVLoadFormat; var StyleNo,
ItemTag: Integer; var ItemName: String);
begin
ItemTag := Integer(StrNew(PChar(Target)));
end;

Can I assume that this string will automatically be deallocated by the control?

Thanks
jamie
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Change the line:
URL := PChar(TRichView(Sender).GetItemTag(ItemNo));
to
URL := PChar(RVData.GetItemTag(ItemNo));

And yes, the string is freed by the control (make sure that rvoTagsArePChars is included in Options property)
jamiemi
Posts: 21
Joined: Sun Oct 30, 2005 3:33 pm

You nailed it

Post by jamiemi »

Thanks
Post Reply