Просмотр исходного кода

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 лет назад
Родитель
Сommit
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
    is the name of the value. The path components will be mapped to XML
    elements, the name will be an element attribute.}
    elements, the name will be an element attribute.}
 
 
+  { TXMLConfig }
+
   TXMLConfig = class(TComponent)
   TXMLConfig = class(TComponent)
   private
   private
     FFilename: String;
     FFilename: String;
@@ -64,6 +66,7 @@ type
   protected
   protected
     Doc: TXMLDocument;
     Doc: TXMLDocument;
     FModified: Boolean;
     FModified: Boolean;
+    FReadOnly: Boolean;
     procedure Loaded; override;
     procedure Loaded; override;
   public
   public
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
@@ -73,6 +76,7 @@ type
     procedure OpenKey(const aPath: DOMString);
     procedure OpenKey(const aPath: DOMString);
     procedure CloseKey;
     procedure CloseKey;
     procedure ResetKey;
     procedure ResetKey;
+    procedure SaveAs(AFileName: string);
 
 
     function  GetValue(const APath: DOMString; const ADefault: DOMString): DOMString; overload;
     function  GetValue(const APath: DOMString; const ADefault: DOMString): DOMString; overload;
     function  GetValue(const APath: DOMString; ADefault: Integer): Integer; overload;
     function  GetValue(const APath: DOMString; ADefault: Integer): Integer; overload;
@@ -92,6 +96,7 @@ type
     property Filename: String read FFilename write SetFilename;
     property Filename: String read FFilename write SetFilename;
     property StartEmpty: Boolean read FStartEmpty write SetStartEmpty;
     property StartEmpty: Boolean read FStartEmpty write SetStartEmpty;
     property RootName: DOMString read FRootName write SetRootName;
     property RootName: DOMString read FRootName write SetRootName;
+    property ReadOnly: Boolean read FReadOnly write FReadOnly;
   end;
   end;
 
 
 
 
@@ -124,9 +129,17 @@ end;
 
 
 procedure TXMLConfig.Flush;
 procedure TXMLConfig.Flush;
 begin
 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
   begin
-    WriteXMLFile(Doc, Filename);
+    WriteXMLFile(Doc, AFilename);
     FModified := False;
     FModified := False;
   end;
   end;
 end;
 end;