Czech English German
 
 EINLEITUNG    LOGON    ÜBER DIE FIRMA    KATALOG    DOWNLOADS    KONTAKT   
     
REGULACE.ORG
 Leistungsangebot
 Downloads
 Referenzen
 Bildnis Galerie
 Geschäftsbedingungen
Produkten
LangMan für Delphi (6)
Software (2)
Articles
Alle Artikel
- Interessante
- LangMan für Delphi
- Laser projector
- Students' years
Suchen
 
Verwenden Sie Stichworte, um ein Produkt zu finden.
Erweiterte Suche
Dynamic generation of texts Autor: Ing. Tomáš Halabala
 
box_bg_l.gif.

If your program generates a statement, a log file, etc. at runtime, it can insert into the file relevant strings from the lexicon, which lists them in the currently selected language. However, this approach has one weakness. After the following language change, the existing content of the statement stays in the original language, while the continuing statement will be in the changed language. Under normal circumstances, there is no reasons for the user to select a different language than the one selected in the beginning and the most suitable one. There are some cases when the change of a language is desirable at runtime of the program, and it is even desirable to change the language of the the entire statement from the beginning not only for the following part following.

For these cases, a new class TLangManStrings and visual component TLangManRichEdit has been created and into the lexicons the method CompleteString and Link property has been added.

Example:

If you have in your application an inserted visual component TMemo, into which the program generates some statement at runtime, and you need the language of the entire statement to be possible to be changed at any time, use the TLangManStrings class. The procedure is as follows:

In the routine of the method of the OnCreate event of the form you will create an object for instance Memo:

Memo := TLangManStrings.Create(Memo1.Lines, MainLexicon);

where Memo1 is the visual component TMemo, and MainLexicon is a language lexicon (TDesignedLexicon or TProgrammableLexicon), which contains all the necessary language strings for the dynamic generation of your statement.

This step can be regarded as a replacement of Memo1.Lines property by a new object Memo. So from this moment on you must change all the text content of Lines property solely by means of the new object Memo of TlangManStrings class! Any manipulation of the strings in the Memo1.Lines property will be done solely by means of the object Memo, and it will be done in the very same way as if you were working directly with Memo1.Lines. For example, a new line will be inserted as follows:

Memo.Add('Text of a new line');

The result will be adding of the string 'Text of a new line' on a new line of the Memo1.Lines property.

Now we come to creating a text translatable by MainLexicon lexicon, which was in the Memo object constructor transferred as the second parameter. So for example if there is a string 'My Text' (current language is the English) on the item with index 2 of the lexicon MainLexicon, you could insert the string directly in the following way:

Memo.Add(MainLexicon.Item[2]);

The effect would be the same as in this case:

Memo.Add('My Text');

The only advantage would be that the just inserted string would be in the currently selected language. In the moment, when the user changed the language of the relevant engine, the inserted text would stay unchanged and in Czech.

However, if you insert the string by means of the the link (Link):

Memo.Add(MainLexicon.Link[2]);

in the given moment in the Memo1 component the same text would be on the line as in previous example, but with the difference that, if the user changed the language, the text on the last line of Memo1.Lines would be automatically transferred into the newly selected language.

In the same way as the method Add work without any difference from the original methods of the TStrings class also other methods such as AddObject, Insert, InsertObject, Delete, Clear, Exchange, Sort and CustomSort of the TlangManStrings class. It is only necessary to pay attention to the fact that the resulting assigning of indexes to strings of the Lines property of the TMemo component may differ from the object of TLangManStrings class. For example, if you have in the component TMemo set an automatic line wrap, the number of lines may increase by the number of wrapping compared to the number of lines in TLangManStrings. This is one more important reason why to follow the rule to approach the original text of the object only by means of the compensatory object TLangManStrings.

The reward is a very impressive on-time independent possibility of changing the language of extensive TStrings texts and again, as it is usual in case of LangMan components, without any demands for programmer's time. Otherwise, he would have to use much more complicated and laborious way to achieve the same result.

Before closing the program, remember to release the memory assigned to the Memo object by means of the method Free:

Memo.Free;

This article was published on Thursday, 26. January 2012.
box_bg_r.gif.
Current Reviews: 0 Bewertung schreiben
Tell a friend
Tell a friend about this article:  
Products related to this article:
LangMan Premium
LangMan Premium
LangMan Ultimate
LangMan Ultimate
LangMan Professional
LangMan Professional
Einholkorb Zeige mehr
0 Artikel
Mein Konto
Ihre Email-Adresse
Ihr Passwort
Währung
Annoncen
Torry's Delphi Pages
     
Copyright © 2008-2024 Tomáš Halabala - REGULACE.ORG