Преглед на файлове

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 -
mazen преди 11 години
родител
ревизия
141ead4e62
променени са 1 файла, в които са добавени 15 реда и са изтрити 2 реда
  1. 15 2
      packages/fcl-xml/src/xmlconf.pp

+ 15 - 2
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
+    SaveAs(FFilename)
+  end;
+end;
+
+procedure TXMLConfig.SaveAs(AFileName: string);
+begin
+  if AFileName <> '' then
   begin
-    WriteXMLFile(Doc, Filename);
+    WriteXMLFile(Doc, AFilename);
     FModified := False;
   end;
 end;