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
Images and hyperlinks
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
to
Or use RichViewActions.
Update 2011-Oct-22:
Starting from TRichView 13.3, simply use Target instead of Integer(StrNew(PChar(Target))).
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);
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;
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.
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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;