{ config.pas } program Config; {$IfDef VER80} uses SnipTool, SnipData, SysUtils, WinTypes, WinProcs, DbiProcs, DbiTypes, DbiErrs; {$Else} uses WinTypes, WinCrt, Strings, DbiProcs, DbiTypes, DbiErrs, SnipTool, SnipData; {$EndIf} {===================================================================== Procedure: DisplayCfgFile(); Input: CfgPath - Path within the CFG file to the desired option within the configuration file. Starts at '\' for the root of the configuration tree. Level - Depth of Recursion. Return: None. Desc: This recursive function is used to display all information within the configuration file. ===================================================================== } procedure DisplayCfgFile(CfgPath: pCHAR; Level: INT16); var rslt: DBIResult; { Value to return } hList: hDBICur; { Handle to the Cursor } szNode: pCHAR; { String which contains the name of the node } pCfgDes: pCFGDesc; { Configuration Descriptor } iLoop: INT16; { Loop variable - used in indenting depending on the depth of the recursion. } BaseSize: INT16; { Length of the Current node } begin { Open the Configuration file - returns the configuration options for the current level in a schema table referenced by hList. } rslt := ChkRslt(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPersistent, CfgPath, hList), DBIERR_NONE, ' Error - OpenCfgInfoList.'); if (rslt = DBIERR_NONE) then begin { Allocate resources } GetMem(szNode, 512); GetMem(pCfgDes, sizeof(CFGDesc)); { Initialize descriptor to 0 } FillChar(pCfgDes^, sizeof(CFGDesc), #0); { Process all nodes/paths Get the next record in the table - contains the next option of the given level in the tree. } while (DbiGetNextRecord(hList, dbiNOLOCK, pCfgDes, nil) = DBIERR_NONE) do begin { Clear the szNode variable } FillChar(szNode^, 512, #0); { Indent according to the depth of the configuration option } for iLoop := 0 to Level do StrCat(szNode, ' '); { Output this node, copying the name of the node to the szNode variable. } StrCat(szNode, pCfgDes^.szNodeName); Screen(StrPas(szNode)); { Process this node if it has sub-nodes } if (pCfgDes^.bHasSubnodes) then begin { Determine if this is a base node } if (Level = 0) then begin StrCopy(szNode, CfgPath); StrCat(szNode, pCfgDes^.szNodeName); end else { if not a base node } begin StrCopy(szNode, CfgPath); StrCat(szNode, '\'); StrCat(szNode, pCfgDes^.szNodeName); end; { Recursively call this function to get information about sub-nodes } DisplayCfgFile(szNode, (Level + 1)); end else { Dump node information, as this node does not have } begin { any sub-nodes } { Clear the szNode variable } FillChar(szNode^, 512, #0); { Indent according to the depth of the configuration option } for iLoop := 0 to Level do begin StrCat(szNode, ' '); end; { Determine the length of the string } BaseSize := StrLen(szNode); { Display the remaining information Display the Description of the node } StrPCopy(@szNode[BaseSize], ' Desc: '+ ''+pCfgDes^.szDescription+''); Screen(StrPas(szNode)); { Display the Type of the node } StrPCopy(@szNode[BaseSize], ' Type: '+ ''+IntToStr(pCfgDes^.iDataType)+''); Screen(StrPas(szNode)); { Display the Value of the node } StrPCopy(@szNode[BaseSize], ' Val: '+pCfgDes^.szValue+' '); Screen(StrPas(szNode)); end; { Initialize descriptor to 0 } FillChar(pCfgDes^, sizeof(CFGDesc), #0); end; { Clean up } FreeMem(szNode, 512); FreeMem(pCfgDes, sizeof(CFGDesc)); if (hList <> nil) then begin ChkRslt(DbiCloseCursor(hList), DBIERR_NONE, ' Error - CloseCursor.'); end; end; end; {===================================================================== Procedure: Configuration(); Input: None. Return: None. Description: This example dumps the information contained in the IDAPI configuration file, as well as displaying which configuration file is being used. ===================================================================== } var sysConf: SYSConfig; { Used for storing the system configuration information - used to determine the location of the configuration file. } begin Screen('*** Configuration Example ***'); Screen(' Initializing IDAPI...'); InitOutput; if (ChkRslt(DbiInit(nil), DBIERR_NONE, ' Error - Init.') <> DBIERR_NONE) then begin CloseOutput; Screen('*** End of Example ***'); exit; end; { Determine which configuration file is being used... } ChkRslt(DbiGetSysConfig(sysConf), DBIERR_NONE, ' Error - GetSysConfig.'); Screen(' Display the information in the currently used'+ ' configuration file: '); Screen(''); Screen(''); Screen(' '+StrPas(sysConf.szIniFile)); Screen(''); { Call the recursive function which dumps information from the configuration file. } DisplayCfgFile ('\', 0) ; Screen(''); Screen(' Exiting IDAPI...'); ChkRslt(Dbiexit, DBIERR_NONE, ' Error - exit'); CloseOutput; Screen('*** End of Example ***'); end.