Derived from TComponent
Unit: Entity
With a TCharToEntityTranslator Component single characters of a text can be replaced by a series of characters.
Properties
TCharToEntityTranslator.DictionaryFile
property DictionaryFile: TFileName
The property DictionaryFile is the name of the file which contains the translation table which specifies the mapping of each single character to its corresponding character series. This is a text file which lines have the following structure:
<SingleCharacter>=<CharacterSeries>
Hint: The zip-archive contains a file Latin1ToHTML.ini with which a text which was created with the help of a text editor and a Latin-1 font can be transformed in an HTML text. That changes for example every 'ß' in the Latin-1 text into 'ß' in the HTML text.
TCharToEntityTranslator.HasEntries (readonly)
property HasEntries: Boolean
Returns 'True' if the translation table has entries, otherwise 'False' is returned.
Methods
TCharToEntityTranslator.Create
constructor Create(AOwner: TComponent); override;
The method Create generates and installs a new instance of TCharToEntityTranslator. With create you can generate a CharToEntityTranslator at runtime. For CharToEntityTranslators which were placed at design time at a form, create will be called automatically.
TCharToEntityTranslator.Translate
function Translate(const source: string): string; virtual;
The function Translate replaces single characters of 'source'
according to the translation table specified in the property 'DictionaryFile' and returns the result in a string. The property 'DictionaryFile' must have been set before to a valid translation table!
TCharToEntityTranslator.ReplaceWhiteSpace
function ReplaceWhiteSpace(const Source: string; const ReplaceChar: Char): string; virtual;
The function ReplaceWhiteSpace replaces each white space character (SPACE, TAB, LF, CR) in the string 'Source' by the character specified in 'ReplaceChar' and returns the result as a string.
Hint: Several succeeding white space characters will be replaced by the same number of 'ReplaceChar' characters.
TCharToEntityTranslator.ReplaceChar
function ReplaceChar(const Source: string; const FindChar, ReplaceChar: Char): string; virtual;
The function ReplaceChar replaces every 'FindChar' character in the string 'Source' by the character specified in 'ReplaceChar' and returns the result in a string.
Hint: This function is very helpful if one wants to hand over a text to a PageProducer. For if the text contains any white space the PageProducer would incorrectly process it. Using the ReplaceWhiteSpace function one can prevent the PageProducer from doing so by replacing each white space in the text by a character which is guarantied not to appear in the text. Example:
with CharToEntityTranslator1 do
NewText:= ReplaceWhiteSpace(OldText,Char(1));
In the OnHTMLTag event of the PageProducers one can reconstruct the original text using the ReplaceChar function to replace the character used before by a SPACE:
with CharToEntityTranslator1 do
OldText:= ReplaceChar(TagParams.Values['Value'],Char(1),' ');
Attention: TABs, LFs and CRs of the original text became all SPACEs now! However, for HTML this usually does not matter.