lcl: added TPropStorageXMLConfig.LoadFromStream+SaveToStream

git-svn-id: trunk@39711 -
This commit is contained in:
mattias 2013-01-01 17:33:40 +00:00
parent f3bbfa5d32
commit d241c00d1f

View File

@ -22,14 +22,17 @@ interface
uses uses
Classes, SysUtils, FileUtil, LCLProc, Forms, PropertyStorage, XMLConf, DOM, Classes, SysUtils, FileUtil, LCLProc, Forms, PropertyStorage, XMLConf, DOM,
LazConfigStorage; XMLRead, XMLWrite, LazConfigStorage;
type type
{ TPropStorageXMLConfig } { TPropStorageXMLConfig }
TPropStorageXMLConfig = class(TXMLConfig) TPropStorageXMLConfig = class(TXMLConfig)
Public Public
procedure DeleteSubNodes (const ARootNode: String); procedure DeleteSubNodes(const ARootNode: String);
procedure LoadFromStream(s: TStream); virtual;
procedure SaveToStream(s: TStream); virtual;
property XMLDoc: TXMLDocument read Doc;
end; end;
{ TCustomXMLPropStorage } { TCustomXMLPropStorage }
@ -93,6 +96,7 @@ type
constructor Create(const Filename: string; LoadFromDisk: Boolean); override; constructor Create(const Filename: string; LoadFromDisk: Boolean); override;
constructor Create(TheXMLConfig: TXMLConfig); constructor Create(TheXMLConfig: TXMLConfig);
constructor Create(TheXMLConfig: TXMLConfig; const StartPath: string); constructor Create(TheXMLConfig: TXMLConfig; const StartPath: string);
constructor Create(s: TStream; const StartPath: string = '');
destructor Destroy; override; destructor Destroy; override;
property XMLConfig: TXMLConfig read FXMLConfig; property XMLConfig: TXMLConfig read FXMLConfig;
property FreeXMLConfig: boolean read FFreeXMLConfig write FFreeXMLConfig; property FreeXMLConfig: boolean read FFreeXMLConfig write FFreeXMLConfig;
@ -141,7 +145,7 @@ end;
function TCustomXMLPropStorage.GetXMLFileName: string; function TCustomXMLPropStorage.GetXMLFileName: string;
begin begin
if (FFileName<>'') then if (FFileName<>'') then
Result:=FFIleName Result:=FFileName
else else
{$ifdef unix} {$ifdef unix}
Result:=IncludeTrailingPathDelimiter(GetEnvironmentVariableUTF8('HOME')) Result:=IncludeTrailingPathDelimiter(GetEnvironmentVariableUTF8('HOME'))
@ -215,6 +219,19 @@ begin
end; end;
end; end;
procedure TPropStorageXMLConfig.LoadFromStream(s: TStream);
var
NewDoc: TXMLDocument;
begin
FreeAndNil(Doc);
ReadXMLFile(Doc,s);
end;
procedure TPropStorageXMLConfig.SaveToStream(s: TStream);
begin
WriteXMLFile(Doc,s);
end;
{ TXMLConfigStorage } { TXMLConfigStorage }
function TXMLConfigStorage.GetFullPathValue(const APath, ADefault: String function TXMLConfigStorage.GetFullPathValue(const APath, ADefault: String
@ -288,7 +305,7 @@ end;
constructor TXMLConfigStorage.Create(const Filename: string; constructor TXMLConfigStorage.Create(const Filename: string;
LoadFromDisk: Boolean); LoadFromDisk: Boolean);
begin begin
FXMLConfig:=TXMLConfig.Create(nil); FXMLConfig:=TPropStorageXMLConfig.Create(nil);
FXMLConfig.StartEmpty:=not LoadFromDisk; FXMLConfig.StartEmpty:=not LoadFromDisk;
FXMLConfig.Filename:=Filename; FXMLConfig.Filename:=Filename;
FFreeXMLConfig:=true; FFreeXMLConfig:=true;
@ -308,6 +325,15 @@ begin
AppendBasePath(StartPath); AppendBasePath(StartPath);
end; end;
constructor TXMLConfigStorage.Create(s: TStream; const StartPath: string);
begin
FXMLConfig:=TPropStorageXMLConfig.Create(nil);
FFreeXMLConfig:=true;
TPropStorageXMLConfig(FXMLConfig).LoadFromStream(s);
if StartPath<>'' then
AppendBasePath(StartPath);
end;
destructor TXMLConfigStorage.Destroy; destructor TXMLConfigStorage.Destroy;
begin begin
if FreeXMLConfig then FreeAndNil(FXMLConfig); if FreeXMLConfig then FreeAndNil(FXMLConfig);