How to: Update text in hyperlink

  • Hi,

    In the editor I add a hyperlink (unsubscribe link) using following code:

    Code
    vAntwoordadres := 'email@mydomain.com';  wpEmailEditor.Changing;  wpEmailEditor.BeginUpdate;  wpEmailEditor.UndoBufferSaveTo(wpEmailEditor.ActivePar, wpuReplaceParTotal);  par := wpEmailEditor.ActiveText.AppendNewPar();  wpEmailEditor.UndoBufferSaveTo(Par, wpuReplaceParTotal);  startobj := par.AppendNewObject(wpobjHyperlink,true,false);  par.Append('Unsubscribe by clicking here');  endobj   := par.AppendNewObject(wpobjHyperlink,true,true);hyperlink  endobj.SetTag(startobj.NewTag);  startobj.Source := 'mailto:' + vAntwoordadres + '?Subject=UNSUBSCRIBE';

    To check if this unsubscribe-link is present in the editor I use following code:

    Code
    function UnsubscribeLinkAvailable(Editor : TWPRichText) : Boolean;var i : Integer;    aList : TWPTextObjList ;begin  Result := False;  aList := TWPTextObjList.Create;  Editor.TextObjectsGetList(aList, wpobjHyperlink, false);  for i := 0 to aList.Count-1 do  begin    if Pos(UpperCase('?Subject=UNSUBSCRIBE'), UpperCase(aList.Items[i].Source)) > 0 then      Result := True;  end;  aList.Free;end;

    Now I need to update the vAntwoordadres (=Emailaddress) in the mailto: by code. Is there a way to accomplish this?

    Code
    if UnsubscribeLinkAvailable(FMailingPerEmail.wpEmailEditor) then
      begin
         // Update Emailaddress
         ????
      end;
    • Offizieller Beitrag

    Pretty complicated insertion code you have here - there is also the high level InputHyperlink function if anybody looks for it.

    The URL of a link is in the Source property. The property EmbeddedText can be used to change or read the text within two markers. Use this property with the start object.

  • Would this be the correct code to update the hyperlink (replace the E-mailaddress)? Or is there a better way?

    Code
    procedure TFMailingPerEmail.BijwerkenAntwoordadresInUitschrijflink(vNewAntwoordadres : String);var i : Integer;    aList : TWPTextObjList ;begin  aList := TWPTextObjList.Create;  wpEmailEditor.TextObjectsGetList(aList, wpobjHyperlink, false);  for i := 0 to aList.Count-1 do  begin    if Pos(UpperCase('Unsubscribe by clicking here'), UpperCase(aList.Items[i].Source)) > 0 then    begin      wpEmailEditor.Changing;      wpEmailEditor.BeginUpdate;      aList.Items[i].Source := 'mailto:' + vNewAntwoordadres + '?Subject=UNSUBSCRIBE';      wpEmailEditor.EndUpdate;      wpEmailEditor.DelayedReformat;    end;  end;  aList.Free;end;


    By the way:
    Thanks for the suggestion about the hyperlink insertion. I've updated my code like:

    Code
    wpEmailEditor.Changing;
      wpEmailEditor.BeginUpdate;
      wpEmailEditor.InputHyperlink('Unsubscribe by clicking here','mailto:' + vAntwoordadres + '?Subject=UNSUBSCRIBE');
      wpEmailEditor.EndUpdate;
      wpEmailEditor.DelayedReformat;