unit ConfigDoc; interface uses Classes, IniFiles, UtilMethods; type TConfigInfo = class private FIniFile: TIniFile; FUnits: TStrings; FStandardXmLib: string; FStandardGclLib: string; FOutputPath: string; FAuditPath: string; FCompanyName: string; FAutoSave: Boolean; FAutoSaveInterval: Integer; FOverRangeType: Integer; FExcelWithMis: Boolean; procedure LoadSectionOfUnitList; procedure LoadSectionOfStdFile; procedure LoadSectionOfPath; procedure LoadSectionOfOptions; procedure LoadIniFile; procedure SaveIniFile; procedure SaveSectionOfStdFile; procedure SaveSectionOfOptions; function GetStandardGclLib: string; function GetStandardXmLib: string; procedure SetStandardGclLib(const Value: string); procedure SetStandardXmLib(const Value: string); function GetOutputPath: string; function GetAuditPath: string; public constructor Create(const AIniFile: string); destructor Destroy; override; property Units: TStrings read FUnits; property StandardXmLib: string read GetStandardXmLib write SetStandardXmLib; property StandardGclLib: string read GetStandardGclLib write SetStandardGclLib; // Path property AuditPath: string read GetAuditPath; property OutputPath: string read GetOutputPath; // Options property CompanyName: string read FCompanyName write FCompanyName; property AutoSave: Boolean read FAutoSave write FAutoSave; property AutoSaveInterval: Integer read FAutoSaveInterval write FAutoSaveInterval; property OverRangeType: Integer read FOverRangeType write FOverRangeType; property ExcelWithMis: Boolean read FExcelWithMis write FExcelWithMis; end; implementation { TConfigInfo } constructor TConfigInfo.Create(const AIniFile: string); begin FIniFile := TIniFile.Create(AIniFile); FUnits := TStringList.Create; LoadIniFile; end; destructor TConfigInfo.Destroy; begin SaveIniFile; FUnits.Free; FIniFile.Free; inherited; end; function TConfigInfo.GetAuditPath: string; begin Result := GetAppFilePath + FAuditPath; end; function TConfigInfo.GetOutputPath: string; begin Result := GetAppFilePath + FOutputPath; end; function TConfigInfo.GetStandardGclLib: string; begin Result := GetAppFilePath + '标准清单\工程量清单\' + FStandardGclLib; end; function TConfigInfo.GetStandardXmLib: string; begin Result := GetAppFilePath + '标准清单\项目节清单\' + FStandardXmLib; end; procedure TConfigInfo.LoadIniFile; begin LoadSectionOfUnitList; LoadSectionOfStdFile; LoadSectionOfPath; LoadSectionOfOptions; end; procedure TConfigInfo.LoadSectionOfOptions; begin FCompanyName := FIniFile.ReadString('Options', 'CompanyName', ''); FAutoSave := FIniFile.ReadBool('Options', 'AutoSave', True); FAutoSaveInterval := FIniFile.ReadInteger('Options', 'AutoSaveInterval', 15); FOverRangeType := FIniFile.ReadInteger('Options', 'OverRangeType', 0); FExcelWithMis := FIniFile.ReadBool('Options', 'ExcelWithMis', False); end; procedure TConfigInfo.LoadSectionOfPath; begin FOutputPath := FIniFile.ReadString('Paths', 'Output', '导出文件\'); FAuditPath := FIniFile.ReadString('Paths', 'AuditPath', '上报批复文件\'); end; procedure TConfigInfo.LoadSectionOfStdFile; begin FStandardXmLib := FIniFile.ReadString('StdFiles', 'XmLib', ''); FStandardGclLib := FIniFile.ReadString('StdFiles', 'GclLib', ''); end; procedure TConfigInfo.LoadSectionOfUnitList; var iIndex: Integer; begin if FIniFile.SectionExists('UnitList') then begin FIniFile.ReadSection('UnitList', FUnits); for iIndex := 0 to FUnits.Count - 1 do FUnits.Strings[iIndex] := FIniFile.ReadString('UnitList', FUnits.Strings[iIndex], ''); end; end; procedure TConfigInfo.SaveIniFile; begin SaveSectionOfStdFile; SaveSectionOfOptions; end; procedure TConfigInfo.SaveSectionOfOptions; begin FIniFile.WriteString('Options', 'CompanyName', FCompanyName); FIniFile.WriteBool('Options', 'AutoSave', FAutoSave); FIniFile.WriteInteger('Options', 'AutoSaveInterval', FAutoSaveInterval); FIniFile.WriteInteger('Options', 'OverRangeType', FOverRangeType); FIniFile.WriteBool('Options', 'ExcelWithMis', FExcelWithMis); end; procedure TConfigInfo.SaveSectionOfStdFile; begin FIniFile.WriteString('StdFiles', 'XmLib', FStandardXmLib); FIniFile.WriteString('StdFiles', 'GclLib', FStandardGclLib); end; procedure TConfigInfo.SetStandardGclLib(const Value: string); begin FStandardGclLib := Value; SaveIniFile; end; procedure TConfigInfo.SetStandardXmLib(const Value: string); begin FStandardXmLib := Value; SaveIniFile; end; end.