Yes, an application should not care about the existence of the prefs.js 
file or not - the file itself might have a different name, or be 
retrieved from some other server, etc.

instead you should just check if the value actually exists by catching 
any thrown exceptions to getIntPref or what have you..

also, nsIPref is deprecated, you should be using nsIPrefService, and 
using .getService() not .createInstance() - if you create a second copy 
of the pref service (which is what createInstance would do) then you're 
sure to corrupt the in memory pref store.

Alec

Markus Hossner wrote:
> Hallo,
> 
> I use this function to get the content of a certain preferences (e.g.
> pmpName="browser.startup.homepage"):
> 
> function pmpReadPref(pmpName, pmpType) {
>    var pref = Components.classes[ "@mozilla.org/preferences;1"
> ].createInstance( nsIPref );
>    var pmpValue = null;
>    switch ( pmpType ) {
>          case pmpB:
>            pmpValue = pref.GetBoolPref(pmpName);
>            break;
>          case pmpN:
>            pmpValue = pref.GetIntPref(pmpName);
>            break;
>          case pmpS:
>            pmpValue = pref.GetCharPref(pmpName);
>            break;
>    }
>    return pmpValue;
> }
> 
> But can perhaps anybody tell me: How can I check if the preferences
> exists, before, I try to get its content.
> 
> Thanks!
> 
> Markus
> 


Reply via email to