From 141ead4e627005cbc0fc4c2bbe12731aaf375e37 Mon Sep 17 00:00:00 2001 From: mazen Date: Thu, 15 May 2014 19:23:44 +0000 Subject: [PATCH] fcl-xml: Added new property to XmlConf to allow opening file in read only mode. Added also a save as method. git-svn-id: trunk@27794 - --- packages/fcl-xml/src/xmlconf.pp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/fcl-xml/src/xmlconf.pp b/packages/fcl-xml/src/xmlconf.pp index f2c3110d2f..aeb27e7663 100644 --- a/packages/fcl-xml/src/xmlconf.pp +++ b/packages/fcl-xml/src/xmlconf.pp @@ -43,6 +43,8 @@ type is the name of the value. The path components will be mapped to XML elements, the name will be an element attribute.} + { TXMLConfig } + TXMLConfig = class(TComponent) private FFilename: String; @@ -64,6 +66,7 @@ type protected Doc: TXMLDocument; FModified: Boolean; + FReadOnly: Boolean; procedure Loaded; override; public constructor Create(AOwner: TComponent); override; @@ -73,6 +76,7 @@ type procedure OpenKey(const aPath: DOMString); procedure CloseKey; procedure ResetKey; + procedure SaveAs(AFileName: string); function GetValue(const APath: DOMString; const ADefault: DOMString): DOMString; overload; function GetValue(const APath: DOMString; ADefault: Integer): Integer; overload; @@ -92,6 +96,7 @@ type property Filename: String read FFilename write SetFilename; property StartEmpty: Boolean read FStartEmpty write SetStartEmpty; property RootName: DOMString read FRootName write SetRootName; + property ReadOnly: Boolean read FReadOnly write FReadOnly; end; @@ -124,9 +129,17 @@ end; procedure TXMLConfig.Flush; begin - if Modified and (Filename <> '') then + if Modified and not FReadOnly then begin - WriteXMLFile(Doc, Filename); + SaveAs(FFilename) + end; +end; + +procedure TXMLConfig.SaveAs(AFileName: string); +begin + if AFileName <> '' then + begin + WriteXMLFile(Doc, AFilename); FModified := False; end; end;