Hyperlink Underline Color

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 331
Joined: Fri Jun 18, 2021 3:07 pm

Hyperlink Underline Color

Post by standay »

Sergey,

Using styletemplates, I was able to get the hyperlink text color to change using this:

Code: Select all

    i := RVEFilervActionNew1.StyleTemplates.FindByName(RVHYPERLINKSTYLETEMPLATENAME);
    RVEFilervActionNew1.StyleTemplates[i].ValidTextPropertiesEditor :=
      '[rvfiUnderline,rvfiColor,rvfiJump,rvfiUnderlineColor]';
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.Color := clWindowText;
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.UnderlineColor := clAqua;
    rve.Style.StyleTemplates := RVEFilervActionNew1.StyleTemplates;
    rve.RVData.DoStyleTemplatesChange;
But no matter what I do, I can't get the underline color to change. Can you tell me how to do that?

Thanks

Stan
standay
Posts: 331
Joined: Fri Jun 18, 2021 3:07 pm

Re: Hyperlink Underline Color

Post by standay »

For now, I put the code below into the RVStyle1ApplyStyle procedure:

Code: Select all

  //Overrides hyperlink styletemplate:
  for i := 1 to rve.Style.TextStyles.Count-1 do
  begin
    if rve.Style.TextStyles[i].Jump then
    begin
      //rve.Style.TextStyles[i].FontName := rve.Style.TextStyles[0].FontName;
      //rve.Style.TextStyles[i].Size := rve.Style.TextStyles[0].Size;
      rve.Style.TextStyles[i].Color := rve.Style.TextStyles[0].Color;
      rve.Style.TextStyles[i].UnderlineColor := clAqua;
    end;
  end;
That works to "force" the hyperlink text colors to be what I want them to be. But sure seems that this:

Code: Select all

    RVEFilervActionNew1.StyleTemplates[i].TextStyle.UnderlineColor := clAqua;
Should work...

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

Re: Hyperlink Underline Color

Post by Sergey Tkachenko »

I made the following test:

In the ActionTest demo, I edited rvActionNew1.StyleTemplates at design time. For "Hyperlink" item, I changed:
  • Color = clWindowText
  • UnderlineColor = clAqua
  • ValidTextPropertiesEditor (this is how ValidTextProperties are called in the Object Inspector) = [rvfiUnderline,rvfiColor,rvfiJump,rvfiUnderlineColor]
I ran the project, created a new document, added a new hyperlink. As it is expected, it is black with aqua underline.

Please tell me what exactly you want to implement. Do you want to apply changes to existing hyperlinks in existing documents?
standay
Posts: 331
Joined: Fri Jun 18, 2021 3:07 pm

Re: Hyperlink Underline Color

Post by standay »

Just trying to get the underline color to change when I paste in a hyper link.

I made a small test program and if I change the rvfiUnderlineColor to true in the component properties of my small test app, the color changes as expected. If I don't change rvfiUnderlineColor in the properties and try to do it just from code:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin

  RVEFilervActionNew1.ExecuteTarget(rve);

    i := RVEFilervActionNew1.StyleTemplates.FindByName(RVHYPERLINKSTYLETEMPLATENAME);
    RVEFilervActionNew1.StyleTemplates[i].ValidTextPropertiesEditor :=
      '[rvfiUnderline,rvfiColor,rvfiJump,rvfiUnderlineColor]';
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.Color := clWindowText;
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.UnderlineColor := clRed;

  RVStyle1.StyleTemplates := RVEFilervActionNew1.StyleTemplates;
  rve.RVData.DoStyleTemplatesChange;

  rve.ApplyStyleTemplate(0);

end;
The underline color does not change. Is my ValidTextPropertiesEditor call wrong? Or the FindByName call wrong? Or am I trying to do something at the wrong time or the wrong order? I would expect it to work from code but I can't seem to get it to do that.

I'll try changing the RVEFilervActionNew1 rvfiUnderlineColor setting in the design time properties in my main app and see if it works there.

If you need more info let me know.

Thanks Sergey

Stan
standay
Posts: 331
Joined: Fri Jun 18, 2021 3:07 pm

Re: Hyperlink Underline Color

Post by standay »

OK, looks like changing the RVEFilervActionNew1 rvfiUnderlineColor setting in the design time ValidTextPropertiesEditor properties in my main app lets the underline color work.

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

Re: Hyperlink Underline Color

Post by Sergey Tkachenko »

This code must work:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
    i := RVEFilervActionNew1.StyleTemplates.FindByName(RVHYPERLINKSTYLETEMPLATENAME);
    RVEFilervActionNew1.StyleTemplates[i].ValidTextProperties := [rvfiUnderline,rvfiColor,rvfiJump,rvfiUnderlineColor];
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.Color := clWindowText;
    RVEFilervActionNew1.StyleTemplates[i].TextStyle.UnderlineColor := clRed;
    RVEFilervActionNew1.ExecuteTarget(rve);
end;
Important: changes are made before executing the action.

ValidTextPropertiesEditor was developed only for design-time support. The standard set editor in Object Inspector does not supports sets with more than 32 elements, so this property needs to be processed specially. It makes no sense to use ValidTextPropertiesEditor at runtime.

I also tried to add your code in the ActionTest demo.
I removed loading the file on start, and add after rvActionNew1.ExecuteTarget(RichViewEdit1):

Code: Select all

 i := rvActionNew1.StyleTemplates.FindByName('Hyperlink');
 rvActionNew1.StyleTemplates[i].ValidTextProperties :=
   [rvfiUnderline,rvfiColor,rvfiJump,rvfiUnderlineColor];
 rvActionNew1.StyleTemplates[i].TextStyle.Color := clWindowText;
 rvActionNew1.StyleTemplates[i].TextStyle.UnderlineColor := clRed;

  RVStyle1.StyleTemplates := rvActionNew1.StyleTemplates;
  RichViewEdit1.RVData.DoStyleTemplatesChange;

  RichViewEdit1.ApplyStyleTemplate(0);
This code works as well. You can see that it works in "Format | Styles" command. And hyperlinks inserted with "Insert | Hyperlink" are black with red underlines, as expected. The same is for auto-detected URLs.

As for pasted URLs, they may have formatting of the source document.
standay
Posts: 331
Joined: Fri Jun 18, 2021 3:07 pm

Re: Hyperlink Underline Color

Post by standay »

ValidTextPropertiesEditor was developed only for design-time support...It makes no sense to use ValidTextPropertiesEditor at runtime.
Yes, that explains what I was seeing, thanks.
You can see that it works in "Format | Styles" command.
Yes, I did something similar in my small test app and had similar results. Getting my changes reflected in the styles dialog was also something I was looking for.
As for pasted URLs, they may have formatting of the source document.
This one I have to keep in mind as I test things. In my main app, I use one rve to display and edit many different files. I reload the last file worked on at startup. I sometimes forget that the saved file does not always reflect my code changes when the file was saved with different stuff in it. Makes it hard to see my changes sometimes.

Thanks Sergey

Stan
Post Reply