Finally, in this step, jumps to other documents and jumps to targets in these documents are added.
1. An Enhanced Dialog Box for Displaying and Selecting Targets:
Again the Hypertext Link dialog box is extended to choose an external file. A Choose File... button is placed on the form that triggers a common dialog.
After the user has chosen a file, its name is displayed in the text box and the file is searched for internal targets:
procedure TForm2.CheckFileForTargets(tfile : String); begin txhidden.LoadSaveAttribute[txEnableLinks] := True; txhidden.Load (tfile, 0, 4, false); FillListboxWithTargets (1); RadioButton2.Checked := True; loadedFile := tfile; End;
For this purpose the file is loaded in a second, invisible Text Control. Then the FieldNext method is used as in step 3 to list all targets.
2. Jumping to an External Target:
To implement the jump to an external link, the code added to the FieldLinkClicked event in step 3 must be extended. The following code does not handle jumps to internet addresses, it only implements jumps to targets in other files. To separate a file from a name of a target, Text Control uses the '#' character. The following code separates the file name and the target's name, loads the file with the Load method and jumps to the target with the FieldGoto method:
Else begin // determine which type of link we have // (see List1_Click()) and remove // the '#' character. If (copy(txtLinkTarget.Text, 0, 1) = '#') Then begin LinkType := txFieldInternalLink; txtLinkTarget.Text := copy(txtLinkTarget.Text, 1, Length(txtLinkTarget.Text) - 1); end Else LinkType := txFieldExternalLink; If tx.FieldAtInputPos <> 0 Then begin // editing an existing hyperlink tx.FieldText := txtLinkedText.Text; tx.FieldType[tx.FieldCurrent] := LinkType; tx.FieldTypeData[tx.FieldCurrent] := txtLinkTarget.Text; end Else begin // insert new hyperlink tx.FieldInsert (txtLinkedText.Text); tx.FieldType[tx.FieldCurrent] := LinkType; tx.FieldTypeData[tx.FieldCurrent] := txtLinkTarget.Text; End; HighlightHyperlinks (tx, Form1.HypertextLinks1.Checked); close; End;
3. Loading and Saving Files containing Hypertext Links:
When an HTML, RTF or Microsoft Word document is loaded, Text Control must convert containing hypertext links to appropriate marked text fields as described above. To perform this, a programmer must set the LoadSaveAttribute (txEnableLinks) before using the Load method. Otherwise hypertext links and target fields are not converted. When a document is saved, marked text fields that represent hypertext links, are always converted to the appropriate format.
If Text Control's proprietary format is used, setting LoadSaveAttribute is not necessary.
More information about hypertext links and a list of all properties, methods and events that can be used with marked text fields, can be found in the chapter Technical Articles - Marked Text Fields - Special Types of Marked Text Fields.