Delphi Examples: DbiOpenCfgInfoList

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Delphi Examples: DbiOpenCfgInfoList

Return to chapter overview

Returns a handle to an in-memory table listing all the nodes in the configuration file accessible by the specified path.

WARNING: Be extremely careful when altering the IDAPI.CFG configuration file. Make absolutely sure that all options and parameters are correct or corruption of the configuration file can, and more than likely, occur.

Example 1: Retrieve a particular value from the IDAPI.CFG configuration file.

This example uses the following input:

 Edit1.Text := GetConfigParameter(PARADOXLEVEL, @Count);

 

NOTE: Param (in this case PARADOXLEVEL) must be a string that contains the path to the node and the node item separated by a semicolon. At the bottom of this page are some of the more popular paths and items that are declared as constants for use with all these examples.

The function is:

function GetConfigParameter(Param: string; Count: pword): string;

var

 hCur: hDBICur;

 rslt: DBIResult;

 Config: CFGDesc;

 Path, Option: String;

 Temp: array[0..255] of char;

begin

 Result := '';

 hCur := nil;

if (Count <> nil) then

   Count^ := 0;

try

  if (Pos(';', Param) = 0) then

    raise EDatabaseError.Create('Invalid parameter passed to' +

      'function.  There must be a semicolon delimited sting passed');

   Path := Copy(Param, 0, Pos(';', Param) - 1);

   Option := Copy(Param, Pos(';', Param) + 1, Length(Param) - Pos(';', Param));

   Check(DbiOpenCfgInfoList(nil, dbiREADONLY, cfgPERSISTENT,

     StrPCopy(Temp, Path), hCur));

   Check(DbiSetToBegin(hCur));

  repeat

     rslt := DbiGetNextRecord(hCur, dbiNOLOCK, @Config, nil);

    if (rslt = DBIERR_NONE) then begin

      if (StrPas(Config.szNodeName) = Option) then

         Result := Config.szValue;

      if (Count <> nil) then

         Inc(Count^);

    end

    else

      if (rslt <> DBIERR_EOF) then

         Check(rslt);

  until (rslt <> DBIERR_NONE);

finally

  if (hCur <> nil) then

     Check(DbiCloseCursor(hCur));

end;

end;

Common paths and items that are declared as constants for use with all these examples

const

 { Here are the parameters used to pass into the cfg functions. These are only a small portion of what types can be passed in. You need to call DbiOpenCfgInfoList with '\' in pszCfgPath to get all possible options if it is not found below. }

 

 { Paradox Driver Settings...  }

 PARADOXNETDIR = '\DRIVERS\PARADOX\INIT\;NET DIR';

 PARADOXVERSION = '\DRIVERS\PARADOX\INIT\;VERSION';

 PARADOXTYPE = '\DRIVERS\PARADOX\INIT\;TYPE';

 PARADOXLANGDRIVER = '\DRIVERS\PARADOX\INIT\;LANGDRIVER';

 PARADOXLEVEL = '\DRIVERS\PARADOX\TABLE CREATE\;LEVEL';

 PARADOXBLOCKSIZE = '\DRIVERS\PARADOX\TABLE CREATE\;BLOCK SIZE';

 PARADOXFILLFACTOR = '\DRIVERS\PARADOX\TABLE CREATE\;FILL FACTOR';

 PARADOXSTRICTINTEGRITY = '\DRIVERS\PARADOX\TABLE CREATE\;STRICTINTEGRITY';

 

 { dBASE Driver Settings...  }

 DBASEVERSION = '\DRIVERS\DBASE\INIT\;VERSION';

 DBASETYPE = '\DRIVERS\DBASE\INIT\;TYPE';

 DBASELANGDRIVER = '\DRIVERS\DBASE\INIT\;LANGDRIVER';

 DBASELEVEL = '\DRIVERS\DBASE\TABLE CREATE\;LEVEL';

 DBASEMDXBLOCKSIZE = '\DRIVERS\DBASE\TABLE CREATE\;MDX BLOCK SIZE';

 DBASEMEMOFILEBLOCKSIZE = '\DRIVERS\DBASE\TABLE CREATE\;MEMO FILE BLOCK SIZE';

 

 { InterBase Driver Settings...  }

 INTERBASESERVERNAME = '\DRIVERS\INTRBASE\DB OPEN\;SERVER NAME';

 INTERBASEUSERNAME = '\DRIVERS\INTRBASE\DB OPEN\;USER NAME';

 INTERBASEOPENMODE = '\DRIVERS\INTRBASE\DB OPEN\;OPEN MODE';