about insert link

General TRichView support forum. Please post your questions here
Post Reply
dutboy
Posts: 5
Joined: Mon Nov 14, 2005 12:19 pm

about insert link

Post by dutboy »

In my program , I insert link text using code under:

Code: Select all

  f:=TfrmInsertLink.Create(self);
  url:=pchar(aRVE.GetCurrentTag);
  if url='' then url:='http://';
  f.edtTarget.Text:=url;
  if f.ShowModal=mrok then
    begin
      FontInfo:=TFontInfo.Create(nil);
      try
        FontInfo.Assign(rvs.TextStyles[4]);
        FontInfo.Color:=f.lblCommonText.Color;
        FontInfo.BackColor:=f.lblCommonBack.Color;
        FontInfo.HoverColor:=f.lblActiveText.Color;
        FontInfo.HoverBackColor:=f.lblActiveBack.Color;
        rvs.TextStyles.Add;
        rvs.TextStyles[rvs.TextStyles.Count-1].Assign(FontInfo);
        rvs.TextStyles[rvs.TextStyles.Count-1].Standard:=false;
        aRVE.applyTextStyle(rvs.TextStyles.Count-1);
        url:=f.edtTarget.Text;
        SetUrlToSelection(url);
        FontInfo.Free;
      except
      end;
    end;
But after do it, all text's format is link now.

How can I restore the format before I insert link?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I missed this question.

As far as I understand, the problem is: if the user types just after the hyperlink, new text is still formated like a hyperlink (continues it)

Two things can be done:
1) Store aRVE.CurTextStyleNo value before applying a hyperlink, and restore it (assign back to aRVE.CurTextStyleNo) just after applying.
2) You should close hyperlink when the user presses space, return or tab character. For example, see this demo:
http://www.trichview.com/support/files/ ... erlink.zip (more info: http://www.trichview.com/forums/viewtopic.php?t=61). It closes hyperlinks only on spaces and returns, but tabs should be added to.

PS: You code adds a new text style every time when executing this command. It's not good. You should reuse existing styles when it's possible. See the same demo.
Post Reply