SUBJECT: Handling string messages with the TMultLang 1.131 component * * * * This technical document contains suggested implementation methods of user defined string messages in your application using the TMultLang package. Strings is frequently used with ShowMessage or MessageDlg functions to display user defined messages. By hardcoding the messages in your source code (e.g. strings between ' ') you will have a hard time to internationalize your application, always try to avoid that. Instead, use the TMultLang component string storage to get the strings when needed. The following implementations show how that should be done. YourStr:=MultLang1.GetString('FileNotFound'); or ShowMessage(MultLang1.GetString('FileNotFound')); This always returns the current language string of the user defined identifier 'FileNotFound'. If you would like to have Nr as identifiers use the IntToStr and StrToInt methods respectively. There are two common options to store and retrieve the strings of the TMultLang component. Option 1. Use one TMultLang component per Form to hold user defined strings (besides the Captions, Hints etc) required by the current Form. Option 2. In the mainform, use two TMultLang components. One which holds standard translations and another which should be a global string storage. You will then be able to re-use different string messages in other forms by using this global component. Ex. YourStr:=MainForm.GlobalMultLang.GetString('FileNotFound'); User defined identifiers (hold strings) can be added to languages in the Language Editor with the 'New String' button. At Run-Time you can add strings to languages by using either the SetString method or using the Import method. More information about those methods can be found in the helpfile. This brings us to the discussion about strings and substrings. There will be cases when you want to display a string like: 'The file PARENT.DBF could not be found' The problem here is that the PARENT.DBF file is not fixed, it can be anything. Delphi already have a built in solutions for this and that is the Format method, an Ex: Format('The file %s could not be found', AFileName) The string contents of the identifier can include substrings of other identifiers, ex: 'I like my &ComputerName&' could return a string like this: 'I Like my Compaq' The above sentence with the ComputerName identifier does not make sense since the real Computer Name should always be the exactly same Name in all languages, in that case you will never need to add an identifier called ComputerName. This only shows how easy it is to use substrings. It is important to know that when using an identifier with the ampersands character around it, the GetString method will replace that identifier with the current language string of that identifier. If the GetString method does not find such string it will be returned as it is (with the identifiers name). The advantage of using the TMultLang component as a string storage is obvious, it will automatically return strings for the current selected language. Another reason is of course the speed, by using the component as storage, strings will be retrieved much quicker than using an external database file like the DBF or Paradox. This is a technical paper distributed by the Author of the TMultLang package. If you have any questions please contact him via the address: Patrik Wang E-Mail: PWang@msn.com Fax: +61 2 3269032 * * * *