Page 1 of 1

Problem with Const strings

Posted: Tue May 06, 2003 1:54 pm
by lenif7780
hello all,

I have created a small projet to test your library.

Create new application. On form1 place tsiLang :) and a button.

Source:
const
rsMessage = 'Hello world';
Procedure Button1Click();
begin
ShowMessage(rsMessage);
end;

Ok, it's really simple ... :lol:

After that I launch the wizard and to translate the const, i go to file/const section/with form...
The wizard found my rsMessage, I click replace.

Here's the new modified code:

Const
rsMessage: string = ''; (* Here your message *)


procedure TMainForm.FormCreate(Sender: TObject);
begin
UpdateStrings;
end;
procedure TMainForm.siLangChangeLanguage(Sender: TObject);
begin
UpdateStrings;
end;
procedure TMainForm.UpdateStrings;
begin
rsMessage := siLang.GetTextOrDefault('rsMessage');
end;

Off course when i compile I get error in updatestrings because const are readonly. Why the wizard do bad change to my code ? Why not only put the siLang.GetTextOrDefault('rsMessage'); into the showmessage ?

I hope you can understand my description and show me what I'm doing bad ?

Thanks,
lenif7780

Posted: Tue May 06, 2003 2:03 pm
by lenif7780
One more question, this component works with customizable menu avaliable from delphi 6: TActionManager, TActionMainMenubar, TActionToolBar ?

Thanks all,

Posted: Tue May 06, 2003 3:03 pm
by gaivans
Hello,

All you need is to allow const assignment for your project. To make this click the IDE menu "Project|Options|Compiler" and check the option "Assignable typed constants", or place into your code the conditional {$J+}.

On your second question the answer is yes. TsiLang components can handle all string properties for TAction objects, such as "Caption" or "Hint".

Posted: Tue May 06, 2003 8:52 pm
by HenrichD
gaivans wrote:Hello,

All you need is to allow const assignment for your project. To make this click the IDE menu "Project|Options|Compiler" and check the option "Assignable typed constants", or place into your code the conditional {$J+}.

On your second question the answer is yes. TsiLang components can handle all string properties for TAction objects, such as "Caption" or "Hint".
The 'assignable typed constant' compiler option is not what he is looking for : the modifications of the source code by the 'const string' expert do not make sense : there is absolutely no reason for this expert to modify resourcestrings in that way - converting them to 'assigned consts' does not make the code more readable or 'better'.

Imho the right way to treat resourcestrings is to use tsilangs capabilities to translate resourcestrings - there is no need to handle them by modifying the source code.

Posted: Wed May 07, 2003 3:25 am
by isiticov
The demonstrated source code snippet has used strings placed in const section not resourcestrings section. And the answer to modify project compiler settings to allow to use Asignable Typed Constants is absolutely correct.

Posted: Wed May 07, 2003 6:08 am
by lenif7780
Ok, I try it and keep you on !

Posted: Wed May 07, 2003 6:53 am
by lenif7780
Too much compiler options, I don't known all of them .. ! ;-)

Ok, one more question:
I have string constant into the const section that must not be translated. When I launch the scan, all the const are retrieved. All my const that must be translated start with the "rs" préfix.
Is it possible to add a scan filter for const ?

Because I try to select only some const with CTRL+M but all my constants are changed. Another strange thing, the wizard change my source add the code to launch method UpdateStrings but the procedure UpdateString is not created ... :? :cry:

Posted: Wed May 07, 2003 7:13 am
by isiticov
Just use {TSI:IGNORE} tag to ignore single line with strings and {TSI:IGNORE ON} / {TSI:IGNORE OFF} to ignore block of lines. This will prevent expert from translating strings from this blocks. Also it would be helpful for you to download User's Guide from our download page and you will find there a lot of useful information as well as tips and tricks.

Posted: Wed May 07, 2003 8:04 am
by lenif7780
Thanks,

I do that ...

Posted: Wed May 07, 2003 11:11 am
by lenif7780
Ok I agree that if I read the user guide, one question of my previous message was unnecessary. But I still with the expert problem. Expert change my const declaration, add UpdateStrings into events but the UpdateStrings procedure itself isn't created !?

Thanks,

Posted: Wed May 07, 2003 1:10 pm
by gaivans
Hello,

We cannot reproduce the situation when "UpdateStrings" is not written to the current module. Could you please provide us with more detailed or give the step-by-step description?

Posted: Wed May 07, 2003 1:10 pm
by HenrichD
isiticov wrote:The demonstrated source code snippet has used strings placed in const section not resourcestrings section. And the answer to modify project compiler settings to allow to use Asignable Typed Constants is absolutely correct.
Sorry - I missed that - you are absolutely right if we look at string constants.

However the const string wizard does modify the resourcestring section in a way which makes the file uncompilable :

resourcestring
rsLanguage: string = ''; (* English *)
rsString1: string = ''; (* Resource String 1 *)
rsString2: string = ''; (* Resource String 2 *)
rsString3: string = ''; (* Resource String 3 *)

Just tested it again and it does not make sense. My personal opinion still is one should use the resourcestring capabilities for resourcestrings so you might want to think about skipping resourcestring section in the const string expert thingy.

Henrich.

Posted: Wed May 07, 2003 1:21 pm
by isiticov
Of course this depends on each developer opinion. And in case you want to prevent expert from replacing the resourcestrings you can always enclose resourcestrings section with {TSI:IGNORE ON} and {TSI: IGNORE OFF} tags. But be aware that translating resource strings is much slower when translating using GetText... methods and this may affect to application's performance in some particular cases. But again in each partucular case developer should select what is best suitable for his/her needs.