Images and hyperlinks

General TRichView support forum. Please post your questions here
Post Reply
stuart
Posts: 8
Joined: Wed Jan 13, 2010 4:48 pm

Images and hyperlinks

Post by stuart »

I am sorry if this has been answered before, but I have look at the demos, and on the forum but am unable to find how to add a hyper link to an image. I am going to (hopefully) use TRichViewEdit to create a simple HTML editor, therfore will be using the SaveHTML method.

I understand how to add a link to selected text, but cannot for the life of me find how to add/edit a link to a picture that has been added using InsertPicture.

Thank you for any help you can give.

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

Post by Sergey Tkachenko »

For inserting a new hyperlink, use InsertHotPicture method.
For converting selected fragment to a hyperlink, call ConvertToHotPicture for all selected pictures.

To support pictures, the demo Assorted\Hyperlinks\CreateHyperlink\ should be changed.
In TForm1.SetTargetToSelection, change the code

Code: Select all

  if Target<>'' then
    for i := StartNo to EndNo do
      rve.SetItemTagEd(i, Integer(StrNew(PChar(Target))))
  else
    for i := StartNo to EndNo do
      rve.SetItemTagEd(i, 0);
to

Code: Select all

  if Target<>'' then
    for i := StartNo to EndNo do begin
      if rve.GetItemStyle(i)=rvsPicture then
        rve.ConvertToHotPicture(i);
      if (rve.GetItemStyle(i)=rvsHotPicture) or (rve.GetItemStyle(i)>=0) then
        rve.SetItemTagEd(i, Integer(StrNew(PChar(Target))))
    end
  else
    for i := StartNo to EndNo do begin
      if rve.GetItemStyle(i)=rvsHotPicture then
        rve.ConvertToPicture(i);
      if (rve.GetItemStyle(i)=rvsPicture) or (rve.GetItemStyle(i)>=0) then
        rve.SetItemTagEd(i, 0);
    end;
Or use RichViewActions.

Update 2011-Oct-22:
Starting from TRichView 13.3, simply use Target instead of Integer(StrNew(PChar(Target))).
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 6:33 pm, edited 1 time in total.
stuart
Posts: 8
Joined: Wed Jan 13, 2010 4:48 pm

Post by stuart »

Sergey

Thank you very much for your quick reply, it worked a treat.

One last thing (I hope). When I set links, and ten save the html using SaveHTML, the links are not saved. Is there something else I need to do?

Thanks again

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

Post by Sergey Tkachenko »

Process OnWriteHyperlink event to assign tag as a hypertext target:

Code: Select all

procedure TForm3.RichViewEdit1WriteHyperlink(Sender: TCustomRichView;
  id: Integer; RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat; var Target, Extras: String);
begin
  Target := PChar(RVData.GetItemTag(ItemNo));
end;
Post Reply