Page 1 of 1
Images and hyperlinks
Posted: Wed Jan 13, 2010 4:52 pm
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
Posted: Wed Jan 13, 2010 5:17 pm
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))).
Posted: Fri Jan 15, 2010 11:44 am
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
Posted: Fri Jan 15, 2010 7:04 pm
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;