How to add an hyperlink style to label items

General TRichView support forum. Please post your questions here
Post Reply
jonjon
Posts: 467
Joined: Sat Aug 27, 2005 4:19 pm

How to add an hyperlink style to label items

Post by jonjon »

Hi,

I'm having a hard time finding out what I'm doing wrong. I used to do it with an older version of Delphi / RV now I can't do it anymore.

I'm trying to set a label item as an hyperlink using the associated RVAction. Target is correctly set and retrieved however, the action's colors is not applied to the labelitem at all.

Step to reproduce:
- Open the MailMerge-LabelItem demo
- Add a standard hyperlink RVAction to a button
- Run the demo and select the first line with the label item
- Click the insert hyperlink button and add a target
- Click OK: the selected text is blue and underlined but the label item isn't

Please help.
jonjon
Posts: 467
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon »

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

Post by Sergey Tkachenko »

There are 2 problems here.

1) Why label items are not blue and underlined after applying hyperlinks?

In this demo, ProtectTextStyleNo=False for all labelitems. However, when ApplyStyleConversion is called with the parameter Recursive=False (like TrvActionInsertHyperlink does), the conversion is not applied to non-text items. This is a bug, it will be fixed in the next update (we plan to upload it in the next couple of days). This parameter was created only to prevent applying to table cells.

2) Why a hyperlink target is not applied to labelitem.Tag? Because TrvActionInsertHyperlink changes tags only for text and pictures. To apply text to labelitems, you need to process TrvActionInsertHyperlink.OnApplyHyperlinkToItem event.
The simplest example of this event:

Code: Select all

procedure TForm1.rvActionInsertHyperlink1ApplyHyperlinkToItem(Sender: TObject;
    Editor: TCustomRichViewEdit; RVData: TCustomRVData; ItemNo: Integer;
    const Target: String) of object;
begin
  if RVData.GetItem(ItemNo) is TRVLabelItemInfo then
     RVData.SetItemTag(ItemNo, Integer(StrNew(PChar(Target))));
end;
This code (after fixing the problem mentioned in (1)) allows applying hyperlink target to selected label items. However, it would broke the demo, because the demo uses labelitems' tags as field codes. If you really need to have labelitems-hyperlinks in this demo, you need to modify:
- OnApplyHyperlinkToItem to allow storing both a field code and a hyperlink target in a tag (for example, they can be separated by '|');
- every part of this demo where labelitem's tags are read (to extract a field code part from a tag string, instead of using the whole string)
- in OnJump event, instead of calling rvActionInsertHyperlink1.GoToLink, extract a target from a tag string, and execute it.
Alternatively, you can use tags to store hyperlinks, and a visible labelitem text to store target.

Update 2011-Oct-22:
For TRichView 13.3+, the code must be

Code: Select all

procedure TForm1.rvActionInsertHyperlink1ApplyHyperlinkToItem(Sender: TObject;
    Editor: TCustomRichViewEdit; RVData: TCustomRVData; ItemNo: Integer;
    const Target: String) of object;
begin
  if RVData.GetItem(ItemNo) is TRVLabelItemInfo then
     RVData.SetItemTag(ItemNo, Target);
end;
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 6:24 pm, edited 1 time in total.
jonjon
Posts: 467
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon »

Sergey Tkachenko wrote:This is a bug, it will be fixed in the next update (we plan to upload it in the next couple of days). This parameter was created only to prevent applying to table cells.
Thank you Sergey, I'll be waiting for this bug fix as I've already implemented your second suggestion. Is it available yet ? If yes, what is the version number ? Thanks.

Regards,

John.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Not yet, planned for this or next week.
jonjon
Posts: 467
Joined: Sat Aug 27, 2005 4:19 pm

Post by jonjon »

Do you know if it'll be beta or stable release ? If beta, would it be possible to extract that particular fix so I can apply it to the latest stable release ?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

It will be released as a stable version. Initially, it was planned as a beta, but releases were delayed and delayed, so I think now it is properly tested. We just need to complete some small things.
Post Reply