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.
How to add an hyperlink style to label items
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
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
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;
- 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.
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.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.
Regards,
John.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: