Problem
In manchen Fällen ist es notwendig globale Einstellungen zu speichern und zu lesen.
Ansatz – Approach
Für diese Zwecke nutze ich ein Include-File, welches einfach mit dem #include Befehl eingebunden werden kann
Vorraussetzungen – Prerequirements
Das Modul /Project/Properties mit den Attributen BB_Key und BB_Value muss bereits angelegt worden sein.
Lösung – Solution
Die Datei setProperty.dxl….
/************************************************
* Author: Bjoern Karpenstein
* Date: 2015-08-05
*
* Description:
* This module stores key/value pairs in
* a module (i.e. for publishing)
*
* Prerequirements:
* Module has to be created before and hast to have
* the BB_Key / BB_Value attributes
* The path has to be customized when using it for
* Different projects
*************************************************/
string propertiesModulePath="/Project/Properties";
Module oldCurrentModule = current;
Module propertiesModule = null;
current=oldCurrentModule;
Object propObject;
string getValue(string theKey)
{
propertiesModule = read(propertiesModulePath, false);
for propObject in propertiesModule do
{
if(propObject."BB_Key" "" == theKey)
{
return propObject."BB_Value" "";
}
}
propObject=null;
close(propertiesModule);
return "n/a";
}
void setValue(string theKey, theValue)
{
string checkIfExists=getValue(theKey);
propertiesModule = edit(propertiesModulePath, false);
if(!canCreate(propertiesModule))
{
ack "Permission for Module: " propertiesModulePath;
halt;
}
if(checkIfExists != "n/a" && !null propObject)
{
propObject."BB_Key" = theKey;
propObject."BB_Value" = theValue;
}
else
{
Object newObject = create(propertiesModule);
newObject."BB_Key" = theKey;
newObject."BB_Value" = theValue;
}
save(propertiesModule);
close(propertiesModule);
}
inkludiere ich anschließen im Kopf des Hauptprogramms mit
#include "path/setProperties.dxl"
und rufe die Methoden
void setValue(string theKey, theValue) - Bsp. setValue("Administrator", "Björn Karpenstein");
string getValue(string theKey) - Bsp. string adminName=getValue("Administrator");
auf.