SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem with Const strings

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite
View previous topic :: View next topic  
Author Message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Tue May 06, 2003 1:54 pm    Post subject: Problem with Const strings Reply with quote

hello all,

I have created a small projet to test your library.

Create new application. On form1 place tsiLang Smile and a button.

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

Ok, it's really simple ... Laughing

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
Back to top
View user's profile Send private message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Tue May 06, 2003 2:03 pm    Post subject: Reply with quote

One more question, this component works with customizable menu avaliable from delphi 6: TActionManager, TActionMainMenubar, TActionToolBar ?

Thanks all,
Back to top
View user's profile Send private message
gaivans



Joined: 29 Nov 2002
Posts: 71

PostPosted: Tue May 06, 2003 3:03 pm    Post subject: Reply with quote

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".
Back to top
View user's profile Send private message AIM Address MSN Messenger
HenrichD



Joined: 06 May 2003
Posts: 8
Location: Cary, NC 27511, USA

PostPosted: Tue May 06, 2003 8:52 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Wed May 07, 2003 3:25 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Wed May 07, 2003 6:08 am    Post subject: Reply with quote

Ok, I try it and keep you on !
Back to top
View user's profile Send private message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Wed May 07, 2003 6:53 am    Post subject: Reply with quote

Too much compiler options, I don't known all of them .. ! Wink

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 ... Confused Crying or Very sad
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Wed May 07, 2003 7:13 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Wed May 07, 2003 8:04 am    Post subject: Reply with quote

Thanks,

I do that ...
Back to top
View user's profile Send private message
lenif7780



Joined: 06 May 2003
Posts: 12

PostPosted: Wed May 07, 2003 11:11 am    Post subject: Reply with quote

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,
Back to top
View user's profile Send private message
gaivans



Joined: 29 Nov 2002
Posts: 71

PostPosted: Wed May 07, 2003 1:10 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message AIM Address MSN Messenger
HenrichD



Joined: 06 May 2003
Posts: 8
Location: Cary, NC 27511, USA

PostPosted: Wed May 07, 2003 1:10 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Wed May 07, 2003 1:21 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group