Unit ConfigFile; { This unit reads some parameters from a config file. It can be used for anything, but the most popular items are the settings for the database. These change over time as our hardware changes. And there should be an easy way to use a different database for testing than for production. Originally these were specified on the command line, but that became a problem for several reasons. One advantage to using a file is that all the programs can read the same values, so if you change the database server, you only have to change the name in one place. The config file is always Config.ini. It is always located in the same directory as the executable file. (This might not be the current directory.) Normally all programs use the same settings. However, I added the idea of a section to allow different programs to have different values. First we look in the specified section. If we can't find the key there, then we look in the common section. If we still can't find it, we use the default that is specified in the code. I don't think that anyone uses sections. It seemed like a good idea at the time. :-) } Interface Const UpdateStockDataProgramSection = 'UpdateStockData'; RealTimeAlertsProgramSection = 'RealTimeAlerts'; RequestOverightDataProgramSection = 'RequestOverightData'; GetStockListProgramSection = 'GetStockList'; Function GetConfigValue(Section, Key : String; Default : String = '') : String; Implementation Uses SysUtils, IniFiles; Const CommonSection = 'Common'; Var Config : TIniFile; Function GetConfigValue(Section, Key : String; Default : String = '') : String; Begin //WriteLn('Section="' + Section + '", Key="' + Key + '", Value = "' + Config.ReadString(Section, Key, 'NOT FOUND') + '"'); //WriteLn('Section="' + CommonSection + '", Key="' + Key + '", Value = "' + Config.ReadString(CommonSection, Key, 'NOT FOUND') + '"'); Result := Config.ReadString(Section, Key, Config.ReadString(CommonSection, Key, Default)) End; Initialization Config := TIniFile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini'); //WriteLn('Reading config file: "' + ExtractFilePath(ParamStr(0)) + 'Config.ini"'); End.