Function to get String ID

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
Riquleme
Posts: 8
Joined: Fri Nov 14, 2008 11:48 pm

Function to get String ID

Post by Riquleme »

Hi,

As we know we read strings form SIL by using siLang->GetTextOrDefault("IDS_0") by default, my question is that is there a funfction that can return String ID in Strings property by providing string contents (AnsiString) and language ID(Int or AnsiString) as parameters? Or something similar to this?

Thanks,
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hi,

Unfortunately, there is no such method.
Best regards,
Igor Siticov.
Riquleme
Posts: 8
Joined: Fri Nov 14, 2008 11:48 pm

Post by Riquleme »

Hi isiticov,

Thanks for your reply.

The reason why I need this is that I have many forms which have not only their own strings, but they also have some common strings, so I think I need to make a common SIL file which should be merged by each form at run-time. That is why I need the access to each newly merged string ID and to use it, otherwise how do I call GetTextOrDefault(stringID), the source code has no idea about what stringID is.

I hope I explain clearly, and is there any alternative to do that ?

Thank you very much!
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello,

This is not an easy task and I would recommend you to re-think if you need to implement this.
If you still decide to use this approach you can use the following:
1. At run-time TsiLang has FStringsColl protected field, which is TsiStringsCollection.
2. This collection holds all strings and their translations. Every item has ID property which is String ID and Values.
3. So you can iterate through all the collection items to check their ID and perform any modifications you need.

Hope this helps.
Best regards,
Igor Siticov.
Jean-Paul Brassard
Posts: 65
Joined: Thu May 08, 2008 7:46 pm

Re: Function to get String ID

Post by Jean-Paul Brassard »

Riquleme wrote:As we know we read strings form SIL by using siLang->GetTextOrDefault("IDS_0") by default, my question is that is there a funfction that can return String ID in Strings property by providing string contents (AnsiString) and language ID(Int or AnsiString) as parameters? Or something similar to this?
We also did need to find IDS from string and developped some code to do it.
1) a method to read SIB files and get all the IDS and their translations;
2) a method to search a given string in a given language and get back its IDS;
3) a method to add these strings into the TsiLang strings collections (as pointed out by Igor).

But you could also fullfill your need with TsiLang standard methods.
1) create a new DataModule on which you drop a TsiLang component;
2) move all your common strings into that module;
3) add a reference to it in your Use sections;
4) add test in your App Initialization to create this DataModule if not done yet.

N.B. While mooving your strings, you should concatenate groups of strings into complete sentences, such as this:

Code: Select all

Dialog('Please check node #' + IntToStr(NodeNumber) + ', it does not respond!')
which should be replace with this:

Code: Select all

Dialog(format(GlobalStr_NodeNotResponding, [NodeNumber]))
Then, in your DataModule, you should find this declaration:

Code: Select all

GlobalStr_NodeNotResponding = 'Please check node #%d, it does not respond!'
Then, in your SIB or SIL, you would be free to reverse the position of the words in your sentence, according to the destination language, such as:

Code: Select all

'Pas de réponse du noeud #%d!'
Jean-Paul Brassard
Quebec, Canada
Post Reply