Hello all, is there a possibility to get the prefix of a formal module without explicitly reading it? My issue is that I get certain IDs from external sources and need to modify the objects with the corresponding ID. Self explanatory, I could just read the first object of the module and parse its ID to get the prefix but I feel like this is not the cleanest way to do so.
Thanks in advance!
Best regards, KaplanA KaplanA - Fri Mar 02 10:39:55 EST 2018 |
Re: Get prefix of a module without entering the module itself I think you are asking if you can get the prefix of the module without actually opening the module (save some time). If so ... the answer is yes. Here is an example to create a module/prefix skipList without actually needing to open any modules. I wouldn't say it is cleaner, but it runs much faster.
Skip buildPrefixList(string aLocations[], Stream aStream){
Item lItem
Skip lSkipList = createString()
for(i = 0; i < sizeof(aLocations) ; i++){
for lItem in folder aLocations[i] do{
if(type(lItem) == "Formal" && !isDeleted(lItem)){
ModName_ lModRef = module(fullName(lItem))
ModuleVersion lVersion = moduleVersion(lModRef)
ModuleProperties lProperties = null
string lError = getProperties(lVersion, lProperties)
if (find(lProperties, "Prefix" ) != null){
string lPrefix = unicodeString(lProperties."Prefix")
if(!find(lSkipList, lPrefix)){
put(lSkipList, lower(lPrefix), fullName(lItem))
}else{
aStream << "Duplicate prefix: " fullName(lItem) " : " lPrefix "\n"
halt
}
}
}
}
}
return lSkipList
}
Also as a side note, if you were to open the module, the prefix is a module attribute. So you don't need to parse the object identifier, you can just reference the module attribute directly. |
Re: Get prefix of a module without entering the module itself davidcs - Fri Mar 02 11:31:34 EST 2018 I think you are asking if you can get the prefix of the module without actually opening the module (save some time). If so ... the answer is yes. Here is an example to create a module/prefix skipList without actually needing to open any modules. I wouldn't say it is cleaner, but it runs much faster.
Skip buildPrefixList(string aLocations[], Stream aStream){
Item lItem
Skip lSkipList = createString()
for(i = 0; i < sizeof(aLocations) ; i++){
for lItem in folder aLocations[i] do{
if(type(lItem) == "Formal" && !isDeleted(lItem)){
ModName_ lModRef = module(fullName(lItem))
ModuleVersion lVersion = moduleVersion(lModRef)
ModuleProperties lProperties = null
string lError = getProperties(lVersion, lProperties)
if (find(lProperties, "Prefix" ) != null){
string lPrefix = unicodeString(lProperties."Prefix")
if(!find(lSkipList, lPrefix)){
put(lSkipList, lower(lPrefix), fullName(lItem))
}else{
aStream << "Duplicate prefix: " fullName(lItem) " : " lPrefix "\n"
halt
}
}
}
}
}
return lSkipList
}
Also as a side note, if you were to open the module, the prefix is a module attribute. So you don't need to parse the object identifier, you can just reference the module attribute directly. Thanks! This helped me a lot. Could you explain me the difference between ModName_ and Module? I am just curious. |
Re: Get prefix of a module without entering the module itself Maybe ... a ModName_ is a reference to a module and a Module is handle to an open module. To get a ModName_ it is not necessary to open the module, but the information you can extract from the reference is also limited. So there may be times where using a module reference (ModName) is appropriate and other times you may have to actually open the module (Module) depending on what you are doing. |
Re: Get prefix of a module without entering the module itself davidcs - Fri Mar 02 12:06:32 EST 2018 Maybe ... a ModName_ is a reference to a module and a Module is handle to an open module. To get a ModName_ it is not necessary to open the module, but the information you can extract from the reference is also limited. So there may be times where using a module reference (ModName) is appropriate and other times you may have to actually open the module (Module) depending on what you are doing. Thanks! I guess this will help me with another issue I was confronted with in the past. |