Page 1 of 1

Function to get String ID

Posted: Mon Mar 09, 2009 11:56 pm
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,

Posted: Wed Mar 11, 2009 11:24 am
by isiticov
Hi,

Unfortunately, there is no such method.

Posted: Wed Mar 11, 2009 6:37 pm
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!

Posted: Fri Mar 13, 2009 3:57 am
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.

Re: Function to get String ID

Posted: Thu Mar 26, 2009 4:20 pm
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!'