GNU gettext for Delphi, C++ Builder and Kylix 1.2 beta
<<< Previous | Introduction | Next >>>

# Forms

It would not be practical to use _() function calls to assign all strings used in a form. If a string has 200 translatable strings, you would have to type 200 lines of code that assigns strings. Therefore, a procedure named `TranslateComponent` was created. This procedure translates all string properties of a specified component, and all components owned by this component. You can use this to translate an entire form by putting this line into the OnCreate event of a form:

    procedure TMyForm.FormCreate (Sender: TObject);
    begin
      TranslateComponent (self);
    end;

This single function call replaces lots of _() function calls, which is nice. And since the strings are put into dfm files, which are already extracted, everything works perfectly, except that some string properties should not be translated.

A default setting is that the .Name property of TComponents are not translated. That wouldn't make much sense, and would break your program. You can specify additional string properties, that should not be translated using the TP_GlobalIgnoreClass and TP_GlobalIgnoreClassProperty procedures:

    TP_GlobalIgnoreClass(TParam);
    TP_GlobalIgnoreClassProperty(TField,'FieldName');

In this example, no TParams will be translated at all, and the Fieldname property of TField objects will not be translated either. These are global settings and should therefore be placed at a global place in your program. It is recommended to put these lines into your .dpr file, see the Section called Sample.dpr in the appendix called "Hello, World" source code>. You can also specify a custom handler for a class like this:

    TP_GlobalHandleClass (TSpecialClass,Myhandler);

You can read more about typical ignores in the appendix called How to handle specific classes>.

<<< Previous | Home | Next >>>
Resourcestrings | Up | Action