trichview.com

trichview.support




Re: Insert Hyperlink to selected text or Image


Return to index


Author

Message

Sergey Tkachenko

Posted: 03/31/2004 20:00:19


Look at the demo in Demos\Delphi\Assorted\Hypertext\CreateHyperlink.

This demo is simple.


RichViewActions' code is much more complicated because they do a lot of

additional work such as:

- smart adjusting selection bounds when calling this action;

- creating a hyperlink style basing on the style of the current text

(TrvActionInsertHyperlink.GetHyperlinkStyleNo) instead of using a style with

the predefined index;

- allowing to implement custom forms instead of the standard one;

- working with pictures;

- inserting new hyperlink, if the selection is empty (even after the smart

adjustment)

- removing the hyperlink (if the target is empty)


The CreateHyperlink demo assumes that there is only text in the editor.

You can modify its procedure:


procedure TForm1.SetURLToSelection(const URL: String);

var i, StartNo, EndNo, StartOffs, EndOffs: Integer;

    rve: TCustomRichViewEdit;

begin

  rve := RichViewEdit1.TopLevelEditor;

  rve.GetSelectionBounds(StartNo, StartOffs, EndNo, EndOffs, True);

  if StartOffs >= rve.GetOffsAfterItem(StartNo) then

    inc(StartNo);

  if EndOffs <= rve.GetOffsBeforeItem(EndNo) then

    dec(EndNo);

  rve.BeginUndoGroup(rvutTag);

  rve.SetUndoGroupMode(True);

  for i := StartNo to EndNo do

  begin

    if rve.GetItemStyle(i)=rvsPicture then begin

      rve.ConvertToHotPicture(i);

      rve.SetItemTagEd(i, Integer(StrNew(PChar(URL))));

      end

    else if rve.GetItemStyle(i)>=0 then

      rve.SetItemTagEd(i, Integer(StrNew(PChar(URL))));

  end;

  rve.SetUndoGroupMode(False);

end;


Note: this procedure must be called only if the selection is not empty.




> The code in the RVAction seems like doing a lot of things but I can't

really

> find out all the usage of it. Can someone provide a more simple but detail

> demo for hyperlink?





Powered by ABC Amber Outlook Express Converter